diff options
author | Miran <narimiran@disroot.org> | 2020-12-03 17:34:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-03 17:34:30 +0100 |
commit | 2220aaeaef74cb6018f4689af8f280db22cb30dd (patch) | |
tree | de6d959299fff78f435a082f4ce3c0b3a5e2a6b5 /lib/pure/strscans.nim | |
parent | 545c406cbeb9d312e29f7363727c0eb9b37b7da7 (diff) | |
download | Nim-2220aaeaef74cb6018f4689af8f280db22cb30dd.tar.gz |
add support for parsing chars in `scanf` macro (#16240)
Diffstat (limited to 'lib/pure/strscans.nim')
-rw-r--r-- | lib/pure/strscans.nim | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/pure/strscans.nim b/lib/pure/strscans.nim index f7032f428..347dbc2ef 100644 --- a/lib/pure/strscans.nim +++ b/lib/pure/strscans.nim @@ -37,6 +37,7 @@ substrings starting with ``$``. These constructions are available: ``$h`` Matches a hex integer. This uses ``parseutils.parseHex``. ``$f`` Matches a floating pointer number. Uses ``parseFloat``. ``$w`` Matches an ASCII identifier: ``[A-Za-z_][A-Za-z_0-9]*``. +``$c`` Matches a single ASCII character. ``$s`` Skips optional whitespace. ``$$`` Matches a single dollar sign. ``$.`` Matches if the end of the input string has been reached. @@ -345,6 +346,12 @@ macro scanf*(input: string; pattern: static[string]; results: varargs[typed]): b else: matchError inc i + of 'c': + if i < results.len and getType(results[i]).typeKind == ntyChar: + matchBind "parseChar" + else: + matchError + inc i of 'b': if i < results.len and getType(results[i]).typeKind == ntyInt: matchBind "parseBin" |