summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-30 00:17:14 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-03-30 00:17:14 -0700
commit4eb00c73e67e8e41eaa3b6f1a1fb5b6ba542b0f5 (patch)
treea730670cf0e41445eecd42490eb22ead1a6e64ec /lib.c
parent0a252c30582c4134c7c1d8d7cacab7cf00f3c2c3 (diff)
downloadtxr-4eb00c73e67e8e41eaa3b6f1a1fb5b6ba542b0f5.tar.gz
txr-4eb00c73e67e8e41eaa3b6f1a1fb5b6ba542b0f5.tar.bz2
txr-4eb00c73e67e8e41eaa3b6f1a1fb5b6ba542b0f5.zip
* lib.c (num_str): Much more accurate test for deciding whether
to treat the number as floating or integer. We can't just look for the presence of E, e or . because these coudl be part of trailing junk for instance "123XYZE." should convert to the integer 123, where "XYZE." is trailing junk. * txr.1: Documented int-str, flo-str and num-str.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index eb756086..186a4a8c 100644
--- a/lib.c
+++ b/lib.c
@@ -1998,9 +1998,12 @@ val flo_str(val str)
val num_str(val str)
{
const wchar_t *wcs = c_str(str);
- if (wcspbrk(wcs, L".eE"))
- return flo_str(str);
- return int_str(str, nil);
+ const wchar_t *nws = wcs + wcsspn(wcs, L"\f\n\r\t\v");
+ const wchar_t *dig = nws + wcsspn(wcs, L"+-");
+
+ if (wcsspn(dig, L"0123456789") == wcsspn(dig, L"0123456789eE."))
+ return int_str(str, nil);
+ return flo_str(str);
}
val chrp(val chr)