summaryrefslogtreecommitdiff
path: root/libstd/chartype.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-15 01:19:56 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-15 01:19:56 -0400
commit00a119d9f78148039fcd0e0641f67e3847c8f357 (patch)
treec31cee93941cf5dc582019f1edbee60d9f2be6b7 /libstd/chartype.myr
parentadd4086c3f6fe23957c9d7707fc3c7720319bf21 (diff)
downloadmc-00a119d9f78148039fcd0e0641f67e3847c8f357.tar.gz
Fix up character type checks.
Diffstat (limited to 'libstd/chartype.myr')
-rw-r--r--libstd/chartype.myr38
1 files changed, 22 insertions, 16 deletions
diff --git a/libstd/chartype.myr b/libstd/chartype.myr
index 677b90e..8241b52 100644
--- a/libstd/chartype.myr
+++ b/libstd/chartype.myr
@@ -1,5 +1,6 @@
use "die.use"
use "sys.use"
+use "types.use"
/*
Tables adapted from plan 9's runetype.c,
@@ -27,6 +28,8 @@ pkg std =
generic charval : (c : char, base : int -> @a::(integral,numeric))
;;
+extern const put : (fmt : byte[:], args : ... -> size)
+
/*
* alpha ranges -
* only covers ranges not in lower||upper
@@ -1058,20 +1061,21 @@ const rtotitle1 = [
0x01f3, 499 /* dz Dz */
]
-const findc = {c, t, sz, nelt, ret
- var l
- var m
+const findc = {c, t, n, nelt, ret
+ var p, m
- /* we're processing in chunks of size
- nelt, so 1 chunk is of length 'nelt' */
- while t.len > nelt
- sz /= 2
- m = sz*nelt
- l = t[m:]
- if c >= l[0]
- t = l[0:m]
+ /*
+ we're processing in chunks of size
+ nelt, so 1 chunk is of length 'nelt'
+ */
+ while n > 1
+ m = n/2
+ p = t[m*nelt:]
+ if c >= p[0]
+ t = p
+ n = n - m
else
- t = t[0:m]
+ n = m
;;
;;
@@ -1147,11 +1151,12 @@ const isspace = {c
const islower = {c
var l
- if findc(c, rtoupper2[:], rtoupper2.len, 2, &l)
+ /* the first character in the toupper table is the lowercase char */
+ if findc(c, rtoupper2[:], rtoupper2.len/3, 3, &l)
if (c >= l[0] && c <= l[1])
-> true
;;
- elif findc(c, rtoupper1[:], rtoupper1.len, 1, &l)
+ elif findc(c, rtoupper1[:], rtoupper1.len/2, 2, &l)
if (c == l[0])
-> true
;;
@@ -1162,11 +1167,12 @@ const islower = {c
const isupper = {c
var l
- if findc(c, rtolower2[:], rtolower2.len, 2, &l)
+ /* the first character in the tolower table is the uppercase char */
+ if findc(c, rtolower2[:], rtolower2.len/3, 3, &l)
if (c >= l[0] && c <= l[1])
-> true
;;
- elif findc(c, rtolower1[:], rtolower1.len, 1, &l)
+ elif findc(c, rtolower1[:], rtolower1.len/2, 2, &l)
if (c == l[0])
-> true
;;