diff options
author | 2022-09-14 13:02:30 -0400 | |
---|---|---|
committer | 2022-09-15 03:02:30 +1000 | |
commit | 3737b424d6c8ef4fb3ea393e9407361a7e095d94 (patch) | |
tree | 732c524436f789780bec41c832e33e2cc99ac3ef /src/lib/util/corestr.cpp | |
parent | 81e5abf05222ce96c70ea29e9ffed3922afcc811 (diff) |
util/corestr.cpp: Changed core_stricmp to take std::string_view parameters. (#10287)
Note that the implementation is still not UTF-8 aware.
Diffstat (limited to 'src/lib/util/corestr.cpp')
-rw-r--r-- | src/lib/util/corestr.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp index 50f2469b14f..1d34e2258a8 100644 --- a/src/lib/util/corestr.cpp +++ b/src/lib/util/corestr.cpp @@ -22,14 +22,22 @@ core_stricmp - case-insensitive string compare -------------------------------------------------*/ -int core_stricmp(const char *s1, const char *s2) +int core_stricmp(std::string_view s1, std::string_view s2) { - for (;;) + auto s1_iter = s1.begin(); + auto s2_iter = s2.begin(); + while (true) { - int c1 = tolower((uint8_t)*s1++); - int c2 = tolower((uint8_t)*s2++); - if (c1 == 0 || c1 != c2) - return c1 - c2; + if (s1.end() == s1_iter) + return (s2.end() == s2_iter) ? 0 : -1; + else if (s2.end() == s2_iter) + return 1; + + const int c1 = tolower(uint8_t(*s1_iter++)); + const int c2 = tolower(uint8_t(*s2_iter++)); + const int diff = c1 - c2; + if (diff) + return diff; } } |