- Fix comparisons involving one or more empty string.
- Fix comparisons against two strings of different lengths.
This commit is contained in:
Tetralux
2020-02-12 10:26:38 +00:00
parent 0b7711684b
commit 1f0c1943da
2 changed files with 13 additions and 1 deletions

View File

@@ -52,6 +52,8 @@ unsafe_string_to_cstring :: proc(str: string) -> cstring {
return cstring(d.data);
}
// Compares two strings, returning a value representing which one comes first lexiographically.
// -1 for `a`; 1 for `b`, or 0 if they are equal.
compare :: proc(lhs, rhs: string) -> int {
return mem.compare(transmute([]byte)lhs, transmute([]byte)rhs);
}