summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-01-04 20:33:14 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-01-04 20:33:14 -0800
commit66dae5a4d72765c80d5cd97f5f16a4d095d79f2f (patch)
tree279d050457fbbfcd291e1160c52c4e5bb1d7d899
parent11ac283d7eda2bac2f19d62d014043f66c8de84c (diff)
downloadtxr-66dae5a4d72765c80d5cd97f5f16a4d095d79f2f.tar.gz
txr-66dae5a4d72765c80d5cd97f5f16a4d095d79f2f.tar.bz2
txr-66dae5a4d72765c80d5cd97f5f16a4d095d79f2f.zip
Revert chr-isdigit/isxdigit, provide new functions.
It was a mistake to change the semantics of the return value of chr-isdigit and chr-isdigit. It breaks code like [partition-by chr-isdigit ...]. The behavior of chr-isdigit and chr-isxdigit is restored to returning t and nil. New chr-digit and chr-xdigit functions are introduced for returning the digit value or nil. * eval.c (eval_init): Register chr-digit and chr-xdigit intrinsics. * lib.c (chr_isdigit, chr_isxdigit): Restore old behavior. (chr_digit, chr_xdigit): New functions. * lib.h (chr_digit, chr_xdigit): Declared. * txr.1: Everything documented.
-rw-r--r--eval.c2
-rw-r--r--lib.c10
-rw-r--r--lib.h2
-rw-r--r--txr.126
4 files changed, 32 insertions, 8 deletions
diff --git a/eval.c b/eval.c
index 438d8476..cbc5e89b 100644
--- a/eval.c
+++ b/eval.c
@@ -5024,6 +5024,7 @@ void eval_init(void)
reg_fun(intern(lit("chr-isascii"), user_package), func_n1(chr_isascii));
reg_fun(intern(lit("chr-iscntrl"), user_package), func_n1(chr_iscntrl));
reg_fun(intern(lit("chr-isdigit"), user_package), func_n1(chr_isdigit));
+ reg_fun(intern(lit("chr-digit"), user_package), func_n1(chr_digit));
reg_fun(intern(lit("chr-isgraph"), user_package), func_n1(chr_isgraph));
reg_fun(intern(lit("chr-islower"), user_package), func_n1(chr_islower));
reg_fun(intern(lit("chr-isprint"), user_package), func_n1(chr_isprint));
@@ -5033,6 +5034,7 @@ void eval_init(void)
reg_fun(intern(lit("chr-isunisp"), user_package), func_n1(chr_isunisp));
reg_fun(intern(lit("chr-isupper"), user_package), func_n1(chr_isupper));
reg_fun(intern(lit("chr-isxdigit"), user_package), func_n1(chr_isxdigit));
+ reg_fun(intern(lit("chr-xdigit"), user_package), func_n1(chr_xdigit));
reg_fun(intern(lit("chr-toupper"), user_package), func_n1(chr_toupper));
reg_fun(intern(lit("chr-tolower"), user_package), func_n1(chr_tolower));
{
diff --git a/lib.c b/lib.c
index 6c51292b..44ef6b0e 100644
--- a/lib.c
+++ b/lib.c
@@ -4025,6 +4025,11 @@ val chr_iscntrl(val ch)
val chr_isdigit(val ch)
{
+ return if2(iswdigit(c_chr(ch)), t);
+}
+
+val chr_digit(val ch)
+{
return if2(iswdigit(c_chr(ch)), minus(ch, chr('0')));
}
@@ -4070,6 +4075,11 @@ val chr_isupper(val ch)
val chr_isxdigit(val ch)
{
+ return tnil(iswxdigit(c_chr(ch)));
+}
+
+val chr_xdigit(val ch)
+{
wchar_t cc = c_chr(ch);
if ('0' <= cc && cc <= '9')
diff --git a/lib.h b/lib.h
index cc8ef265..0872c089 100644
--- a/lib.h
+++ b/lib.h
@@ -717,6 +717,7 @@ val chr_isalpha(val ch);
val chr_isascii(val ch);
val chr_iscntrl(val ch);
val chr_isdigit(val ch);
+val chr_digit(val ch);
val chr_isgraph(val ch);
val chr_islower(val ch);
val chr_isprint(val ch);
@@ -726,6 +727,7 @@ val chr_isblank(val ch);
val chr_isunisp(val ch);
val chr_isupper(val ch);
val chr_isxdigit(val ch);
+val chr_xdigit(val ch);
val chr_toupper(val ch);
val chr_tolower(val ch);
val int_chr(val ch);
diff --git a/txr.1 b/txr.1
index fb2a91a6..0a1283c0 100644
--- a/txr.1
+++ b/txr.1
@@ -17643,17 +17643,22 @@ ranges from 0 to 31, or is 127. In other words, any non-printable ASCII
character. For other characters, it returns
.codn nil .
-.coNP Function @ chr-isdigit
+.coNP Functions @ chr-isdigit and @ chr-digit
.synb
.mets (chr-isdigit << char )
+.mets (chr-digit << char )
.syne
.desc
If
.meta char
-is is an ASCII digit character,
+is is an ASCII decimal digit character,
.code chr-isdigit
-returns the integer value, 0 to 9, corresponding to that character.
-Otherwise, it returns
+returns the value
+.code t
+and
+.code chr-digit
+returns the integer value corresponding to that digit character,
+a value in the range 0 to 9. Otherwise, both functions return
.codn nil .
.coNP Function @ chr-isgraph
@@ -17800,18 +17805,23 @@ if
is an ASCII upper case letter. Otherwise it returns
.codn nil .
-.coNP Function @ chr-isxdigit
+.coNP Function @ chr-isxdigit and @ chr-xdigit
.synb
.mets (chr-isxdigit << char )
+.mets (chr-xdigit << char )
.syne
.desc
If
.meta char
is a hexadecimal digit character,
.code chr-isxdigit
-returns its integer value 0 to 15.
-Otherwise it returns
-.codn nil .
+returns the value
+.code t
+and
+.code chr-xdigit
+returns the integer value corresponding to that digit character,
+a value in the range 0 to 15. Otherwise, both functions returns
+.codn nil .
A hexadecimal digit is one of the ASCII
digit characters