diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-12-23 06:58:09 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-12-23 06:58:09 -0800 |
commit | 5335d788dc601a50fc26319d39b21bdcaf1457b6 (patch) | |
tree | 76462febe097531a53d57a6db5848d0013bdab27 /lib.c | |
parent | 7aacecd153ecfdd7b5c480dc419d4823e896ef1c (diff) | |
download | txr-5335d788dc601a50fc26319d39b21bdcaf1457b6.tar.gz txr-5335d788dc601a50fc26319d39b21bdcaf1457b6.tar.bz2 txr-5335d788dc601a50fc26319d39b21bdcaf1457b6.zip |
chr-isdigit and chr-isxdigit return value.
* lib.c (chr_isdigit, chr_isxdigit): Return the integer value
rather than the symbol t, which can be exploited to write
more compact scanning code.
* txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -4025,7 +4025,7 @@ val chr_iscntrl(val ch) val chr_isdigit(val ch) { - return tnil(iswdigit(c_chr(ch))); + return if2(iswdigit(c_chr(ch)), minus(ch, chr('0'))); } val chr_isgraph(val ch) @@ -4070,7 +4070,18 @@ val chr_isupper(val ch) val chr_isxdigit(val ch) { - return tnil(iswxdigit(c_chr(ch))); + wchar_t cc = c_chr(ch); + + if ('0' <= cc && cc <= '9') + return num_fast(cc - '0'); + + if ('A' <= cc && cc <= 'F') + return num_fast(cc - 'A' + 10); + + if ('a' <= cc && cc <= 'a') + return num_fast(cc - 'a' + 10); + + return nil; } val chr_toupper(val ch) |