compare.ha (621B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 use sort::cmp; 5 6 // Compares two strings by their Unicode codepoint sort order. Zero is returned 7 // if the strings are equal, a negative value if a is less than b, or a positive 8 // value if a is greater than b. 9 export fn compare(a: str, b: str) int = { 10 return cmp::strs(&a, &b); 11 }; 12 13 @test fn compare() void = { 14 assert(compare("ABC", "ABC") == 0); 15 assert(compare("ABC", "AB") > 0); 16 assert(compare("AB", "ABC") < 0); 17 assert(compare("BCD", "ABC") > 0); 18 assert(compare("ABC", "こんにちは") < 0); 19 assert(compare("ABC", "abc") < 0); 20 };