aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkatherine <ageha@airen-no-jikken.icu>2019-12-18 08:39:17 -0700
committerkatherine <ageha@airen-no-jikken.icu>2019-12-18 08:39:17 -0700
commit4fd21e3125c3003ecd0ae28c50c8656b62faefba (patch)
tree9d421b6cc0acfd7ccf5d3a4bd4677717ce01f77a
parent197d36e32ddf85b49e82d5b84b9170f25f844ecb (diff)
downloadsimple-opt-4fd21e3125c3003ecd0ae28c50c8656b62faefba.tar.gz
allow some two-char c string escape codesHEADmaster
\a, \b, \f, \n, \r, \t, \v
-rw-r--r--doc/interface.md5
-rw-r--r--simple-opt.h36
2 files changed, 38 insertions, 3 deletions
diff --git a/doc/interface.md b/doc/interface.md
index 978ecb3..0882acd 100644
--- a/doc/interface.md
+++ b/doc/interface.md
@@ -115,8 +115,9 @@ floating point number that can be read by the standard library `strtod`
function and stored in a `double` type. this includes arguments like "4.9",
"-1.2e20", "infinity", or "nan".
-arguments acceptable to type `SIMPLE_OPT_CHAR` may be any single-byte
-character.
+arguments acceptable to type `SIMPLE_OPT_CHAR` may be any single-byte character
+or one of the following two-character escape sequences: `\a`, `\b`, `\f`, `\n`,
+`\r`, `\t`, `\v`.
arguments acceptable to type `SIMPLE_OPT_STRING` may be any string of
characters the user passes.
diff --git a/simple-opt.h b/simple-opt.h
index d85ee3d..b298975 100644
--- a/simple-opt.h
+++ b/simple-opt.h
@@ -195,8 +195,42 @@ strmatch_out:
return true;
case SIMPLE_OPT_CHAR:
- if (strlen(s) != 1)
+ if (strlen(s) == 2 && s[0] == '\\') {
+ switch (s[1]) {
+ case '0':
+ o->val.v_char = '\0';
+ break;
+ case 'a':
+ o->val.v_char = '\a';
+ break;
+ case 'b':
+ o->val.v_char = '\b';
+ break;
+ case 't':
+ o->val.v_char = '\t';
+ break;
+ case 'n':
+ o->val.v_char = '\n';
+ break;
+ case 'v':
+ o->val.v_char = '\v';
+ break;
+ case 'f':
+ o->val.v_char = '\f';
+ break;
+ case 'r':
+ o->val.v_char = '\r';
+ break;
+ case '\\':
+ o->val.v_char = '\\';
+ break;
+ default:
+ return false;
+ }
+ return true;
+ } else if (strlen(s) != 1) {
return false;
+ }
o->val.v_char = s[0];
return true;