summaryrefslogtreecommitdiff
path: root/lib/std/cmp.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-10-15 13:15:41 -0700
committerOri Bernstein <ori@eigenstate.org>2015-10-15 13:15:41 -0700
commit6ae90fe67572c8feeee655abeb80d1e32aa587bd (patch)
tree8370b175266ae4ff29294c2829c658084ea0805a /lib/std/cmp.myr
parentd3cad93205eb0f2e2dbbead396c2a976face45ba (diff)
downloadmc-6ae90fe67572c8feeee655abeb80d1e32aa587bd.tar.gz
Add case insensitive comparison functions.
Diffstat (limited to 'lib/std/cmp.myr')
-rw-r--r--lib/std/cmp.myr31
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/std/cmp.myr b/lib/std/cmp.myr
index 8c01bfc..b5e026d 100644
--- a/lib/std/cmp.myr
+++ b/lib/std/cmp.myr
@@ -1,5 +1,7 @@
use "extremum.use"
use "types.use"
+use "utf.use"
+use "chartype.use"
pkg std =
type order = union
@@ -11,8 +13,11 @@ pkg std =
generic numcmp : (a : @a, b : @a -> order)
const strcmp : (a : byte[:], b : byte[:] -> order)
const strncmp : (a : byte[:], b : byte[:], n : size -> order)
+ const strcasecmp : (a : byte[:], b : byte[:] -> order)
;;
+extern const put : (str : byte[:], args : ... -> int64)
+
generic numcmp = {a, b
if a < b
-> `Before
@@ -42,7 +47,6 @@ const strcmp = {a, b
else
-> `Equal
;;
-
}
const strncmp = {a, b, n
@@ -51,3 +55,28 @@ const strncmp = {a, b, n
-> strcmp(a, b)
}
+
+const strcasecmp = {a, b
+ var ca, cb
+
+ while a.len > 0 && b.len > 0
+ (ca, a) = std.striter(a)
+ (cb, b) = std.striter(b)
+ ca = toupper(ca)
+ cb = toupper(cb)
+ std.put("{}, {}\n", ca, cb)
+ if ca < cb
+ -> `Before
+ elif ca > cb
+ -> `After
+ ;;
+ ;;
+ if a.len < b.len
+ -> `Before
+ elif a.len > b.len
+ -> `After
+ else
+ -> `Equal
+ ;;
+}
+