From a40017ef86c446ee2569b8c97680701625161f28 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Fri, 14 Jun 2024 14:32:12 +0100 Subject: [PATCH] [+] AuCodepointsIsEqualIgnoreCase --- Include/auROXTL/auStringUtils.hpp | 70 ++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/Include/auROXTL/auStringUtils.hpp b/Include/auROXTL/auStringUtils.hpp index 7b86513..090b7bd 100644 --- a/Include/auROXTL/auStringUtils.hpp +++ b/Include/auROXTL/auStringUtils.hpp @@ -12,13 +12,14 @@ Implements: AuStringContains, AuEndsWith, AuStartsWith, AuReplaceAll, AuSplitString (views), AuSplitStringLegacy (returns an array of strings instead of views) AuToLower(char), AuToUpper(char), AuToLower(view), AuToUpper(view). - Implements: AuCodepointsTransform, AuCodepointsTransformASCIIOp, AuCodepointsToLower, AuCodepointsToUpper, + Implements: AuCodepointsTransform, AuCodepointsTransformASCIIOp, AuCodepointsForEach, AuCodepointsToLower, AuCodepointsToUpper, AuCodepointsCount, AuCodepointsNextLength, AuCodepointsDecode, AuCodepointsEncodeInto, AuCodepointsGetByteOffset(CodepointOffset_t),AuCodepointsGetByteLength(CodepointOffset_t), AuCodepointsFindByteOffset[Unsafe], AuCodepointsFindCodepointOffset(view, CodepointOffset_t), AuCodepointsFindCodepointOffset(CodepointByteOffset_t), AuCodepointsContains, AuCodepointsReplaceAll, AuCodepointsSplitString (views), AuCodepointsFindPreviousValidByteOffsetFromOffset, AuCodepointsFindPreviousValidByteOffsetFromByteOffset + AuCodepointsIsEqualIgnoreCase For translating between locales (including utf8-32), defer to AuLocale (Aurora::Locale) in the Aurora Runtime. ***/ @@ -534,6 +535,73 @@ static bool AuCodepointsForEach(T op, const AuROString &in) return true; } +static bool AuCodepointsIsEqualIgnoreCase(const AuROString &inA, + const AuROString &inB) +{ + if (inA.size() != + inB.size()) + { + return false; + } + + if (inA.empty()) + { + return true; + } + + const char *pItr = inA.data(); + const char *pItr2 = inB.data(); + const char *pEnd = pItr + inA.length(); + + while (pItr < pEnd) + { + AuUInt32 c {}; + + if ((c = *pItr) <= 0x7FU) + { + if (AuToLower(c) != AuToLower(*pItr2)) + { + return false; + } + ++pItr2; + ++pItr; + } + else + { + AuUInt32 nby {}; + + if ((*pItr & 0xC0U) != 0xC0U) + { + return AuMemcmp(pItr, pItr2, pEnd - pItr) == 0; + } + + for (AuUInt8 b = *pItr; (b & 0x80U) != 0; b <<= 1, ++nby) + { + } + + if (nby > kAuCodepointUTF8MaxBytes) + { + return AuMemcmp(pItr, pItr2, pEnd - pItr) == 0; + } + + if (AuUInt(pEnd - pItr) < AuUInt(nby)) + { + return AuMemcmp(pItr, pItr2, pEnd - pItr) == 0; + } + + if (AuMemcmp(pItr, pItr2, nby) != 0) + { + return false; + } + + pItr += nby; + pItr2 += nby; + } + } + + return true; +} + static auline CodepointByteOffset_t AuCodepointsGetByteOffset(const AuROString &in, CodepointOffset_t uCodepointIndex) {