hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 475e50fe3d81bb50983e6b122e7a3629967b6cd2
parent bd52e831d9fb1024c98ef5a1f501a408a3a8328c
Author: Sebastian <sebastian@sebsite.pw>
Date:   Wed, 13 Apr 2022 20:33:47 -0400

ascii: remove strcmp

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mascii/strcmp.ha | 53-----------------------------------------------------
Mcmd/haredoc/sort.ha | 4++--
Mfnmatch/fnmatch.ha | 5++---
Mhare/types/store.ha | 4++--
4 files changed, 6 insertions(+), 60 deletions(-)

diff --git a/ascii/strcmp.ha b/ascii/strcmp.ha @@ -3,51 +3,6 @@ // (c) 2021 Eyal Sawady <ecs@d2evs.net> use strings; -// Compares two strings by their ASCII sort order. If either string is not -// entirely composed of ASCII characters, void is returned. Otherwise, zero is -// returned if the strings are equal, a negative value if a is less than b, or a -// positive value if a is greater than b. -export fn strcmp(a: str, b: str) (int | void) = { - let a = strings::iter(a), b = strings::iter(b); - for (true) { - let ra = match (strings::next(&a)) { - case void => - match (strings::next(&b)) { - case void => - return 0; - case rune => - for (true) match (strings::next(&b)) { - case void => - break; - case let r: rune => - if (!valid(r)) return; - }; - return -1; - }; - case let r: rune => - yield r; - }; - let rb = match (strings::next(&b)) { - case void => - for (true) match (strings::next(&a)) { - case void => - break; - case let r: rune => - if (!isascii(r)) return; - }; - return 1; - case let r: rune => - yield r; - }; - if (!valid(ra) || !valid(rb)) { - return; - }; - if (ra != rb) { - return ra: u32: int - rb: u32: int; - }; - }; -}; - // Compares two strings by their ASCII sort order, treating all capital letters // as their lowercase counterpart (i.e. a case-insensitive comparison is // performed). If either string is not entirely composed of ASCII characters, @@ -97,13 +52,5 @@ export fn strcasecmp(a: str, b: str) (int | void) = { }; @test fn strcmp() void = { - assert(strcmp("ABC", "ABC") as int == 0); - assert(strcmp("ABC", "AB") as int > 0); - assert(strcmp("AB", "ABC") as int < 0); - assert(strcmp("BCD", "ABC") as int > 0); - assert(strcmp("ABC", "こんにちは") is void); - assert(strcmp("ABC", "ABCこんにちは") is void); - assert(strcmp("ABCこんにちは", "AB") is void); - assert(strcmp("ABC", "abc") as int < 0); assert(strcasecmp("ABC", "abc") as int == 0); }; diff --git a/cmd/haredoc/sort.ha b/cmd/haredoc/sort.ha @@ -1,9 +1,9 @@ // License: GPL-3.0 // (c) 2021 Drew DeVault <sir@cmpwn.com> // (c) 2021 Eyal Sawady <ecs@d2evs.net> -use ascii; use hare::ast; use sort; +use strings; type summary = struct { constants: []ast::decl, @@ -98,7 +98,7 @@ fn decl_cmp(a: const *void, b: const *void) int = { return -1; }; const id_a = decl_ident(a), id_b = decl_ident(b); - return ascii::strcmp(id_a[len(id_a) - 1], id_b[len(id_b) - 1]) as int; + return strings::strcmp(id_a[len(id_a) - 1], id_b[len(id_b) - 1]); }; fn decl_ident(decl: ast::decl) ast::ident = { diff --git a/fnmatch/fnmatch.ha b/fnmatch/fnmatch.ha @@ -330,9 +330,8 @@ fn match_ctype(it: *strings::iterator, c: rune) (bool | errors::invalid) = { type funcmap = (str, *fn(c: rune) bool); -fn cmp(a: const *void, b: const *void) int = { - return ascii::strcmp((a: *funcmap).0, *(b: const *str)): int; -}; +fn cmp(a: const *void, b: const *void) int = + strings::strcmp((a: *funcmap).0, *(b: const *str)); fn ctype_name_to_func(name: str) nullable *fn(c: rune) bool = { const map: [_]funcmap = [ diff --git a/hare/types/store.ha b/hare/types/store.ha @@ -2,10 +2,10 @@ // (c) 2021 Alexey Yerin <yyp@disroot.org> // (c) 2021 Drew DeVault <sir@cmpwn.com> // (c) 2021 Eyal Sawady <ecs@d2evs.net> -use ascii; use errors; use hare::ast; use sort; +use strings; def BUCKETS: size = 65535; @@ -508,7 +508,7 @@ fn tuple_from_ast( fn field_cmp(a: const *void, b: const *void) int = { const a = a: const *struct_field, b = b: *const struct_field; - return ascii::strcmp(a.name, b.name) as int; + return strings::strcmp(a.name, b.name); }; fn type_finish(t: *_type) void = {