Browse Source

allow some two-char c string escape codes

\a, \b, \f, \n, \r, \t, \v
tags/v1.4.2
katherine 10 months ago
parent
commit
4fd21e3125
Signed by: ageha GPG Key ID: 62E17859D559AEF3
2 changed files with 38 additions and 3 deletions
  1. +3
    -2
      doc/interface.md
  2. +35
    -1
      simple-opt.h

+ 3
- 2
doc/interface.md View File

@@ -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.


+ 35
- 1
simple-opt.h View File

@@ -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;


Loading…
Cancel
Save