From 5335d788dc601a50fc26319d39b21bdcaf1457b6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 23 Dec 2015 06:58:09 -0800 Subject: 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. --- lib.c | 15 +++++++++++++-- txr.1 | 35 ++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lib.c b/lib.c index 05ccb45a..2aa5029d 100644 --- a/lib.c +++ b/lib.c @@ -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) diff --git a/txr.1 b/txr.1 index 27e72bcd..003ace07 100644 --- a/txr.1 +++ b/txr.1 @@ -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 -- cgit v1.2.3