hare

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

commit dbbc122baeb23ffb63486766014bd45843f68432
parent 648b862b5e7f20e48d299581e46d1ce04acc9616
Author: Sebastian <sebastian@sebsite.pw>
Date:   Tue, 22 Feb 2022 18:46:18 -0500

ascii: always check if strings are ASCII in strcmp funcs

The documentation for strcmp and strcasecmp states that if either string
isn't composed entirely of ASCII characters, then void is returned.
However, prior to this commit, if the lengths of the two strings didn't
match, this check wasn't performed on the remainder of the longer
string. The behavior of these functions now matches their documentation.

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

Diffstat:
Mascii/strcmp.ha | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/ascii/strcmp.ha b/ascii/strcmp.ha @@ -16,6 +16,12 @@ export fn strcmp(a: str, b: str) (int | void) = { case void => return 0; case rune => + for (true) match (strings::next(&b)) { + case void => + break; + case let r: rune => + if (!isascii(r)) return; + }; return -1; }; case let r: rune => @@ -23,6 +29,12 @@ export fn strcmp(a: str, b: str) (int | void) = { }; 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; @@ -51,6 +63,12 @@ export fn strcasecmp(a: str, b: str) (int | void) = { case void => return 0; case rune => + for (true) match (strings::next(&b)) { + case void => + break; + case let r: rune => + if (!isascii(r)) return; + }; return -1; }; case let r: rune => @@ -58,6 +76,12 @@ export fn strcasecmp(a: str, b: str) (int | void) = { }; 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;