From 3737b424d6c8ef4fb3ea393e9407361a7e095d94 Mon Sep 17 00:00:00 2001 From: npwoods Date: Wed, 14 Sep 2022 13:02:30 -0400 Subject: util/corestr.cpp: Changed core_stricmp to take std::string_view parameters. (#10287) Note that the implementation is still not UTF-8 aware. --- src/lib/util/corestr.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/lib/util/corestr.cpp') 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; } } -- cgit v1.2.3-70-g09d2