diff options
| author | Shane Shrybman <shrybman@teksavvy.com> | 2026-02-12 10:54:59 -0500 |
|---|---|---|
| committer | Shane Shrybman <shrybman@teksavvy.com> | 2026-02-12 10:54:59 -0500 |
| commit | 871ad165015f61f2225eb5f58db135984f65fade (patch) | |
| tree | 30322d9adcc93cb7acc096a571d6f49b637c148c /core/strings | |
| parent | a484937fb7b29a9ef7b5087cf11f5104a1825dfc (diff) | |
Add the length checks back to string.compare()
Diffstat (limited to 'core/strings')
| -rw-r--r-- | core/strings/strings.odin | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/core/strings/strings.odin b/core/strings/strings.odin index 9b75c558b..c19bf8c37 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -242,7 +242,13 @@ Returns: - result: `-1` if `lhs` comes first, `1` if `rhs` comes first, or `0` if they are equal */ compare :: proc "contextless" (lhs, rhs: string) -> (res: int) { - return runtime.string_cmp(lhs, rhs) + res = runtime.string_cmp(lhs, rhs) + if res == 0 && len(lhs) != len(rhs) { + return len(lhs) <= len(rhs) ? -1 : +1 + } else if len(lhs) == 0 && len(rhs) == 0 { + return 0 + } + return res } /* |