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 | |
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.
-rw-r--r-- | lib.c | 15 | ||||
-rw-r--r-- | txr.1 | 35 |
2 files changed, 35 insertions, 15 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) @@ -17646,11 +17646,11 @@ character. For other characters, it returns .mets (chr-isdigit << char ) .syne .desc -This function returns -.code t -if the character +If .meta char -is is an ASCII digit. +is is an ASCII digit character, +.code chr-isdigit +returns the integer value, 0 to 9, corresponding to that character. Otherwise, it returns .codn nil . @@ -17803,19 +17803,28 @@ is an ASCII upper case letter. Otherwise it returns .mets (chr-isxdigit << char ) .syne .desc -This function returns -.code t -if +If .meta char -is a hexadecimal digit. One of the ASCII -letters +is a hexadecimal digit character, +.code chr-isxdigit +returns its integer value 0 to 15. +Otherwise it returns +.codn nil . + +A hexadecimal digit is one of the ASCII +digit characters +.code 0 +through +.codn 9 , +or else one of the letters .code A through -.codn F , -or their lower-case equivalents, or an ASCII digit -.code 0 +.code F +or their lower-case equivalents +.code a through -.codn 9 . +.code f +denoting the values 10 to 15. .coNP Function @ chr-toupper .synb |