Browse Source

Fix for case-insensitive comparison of extended UTF8 unicode chars, and some refactoring of CharacterFunctions.

tags/2021-05-28
jules 9 years ago
parent
commit
36a8380e4c
2 changed files with 37 additions and 28 deletions
  1. +0
    -6
      modules/juce_core/text/juce_CharPointer_UTF8.h
  2. +37
    -22
      modules/juce_core/text/juce_CharacterFunctions.h

+ 0
- 6
modules/juce_core/text/juce_CharPointer_UTF8.h View File

@@ -420,13 +420,7 @@ public:
/** Compares this string with another one. */
int compareIgnoreCase (const CharPointer_UTF8 other) const noexcept
{
#if JUCE_MINGW || (JUCE_WINDOWS && JUCE_CLANG)
return CharacterFunctions::compareIgnoreCase (*this, other);
#elif JUCE_WINDOWS
return stricmp (data, other.data);
#else
return strcasecmp (data, other.data);
#endif
}
/** Compares this string with another one, up to a specified number of characters. */


+ 37
- 22
modules/juce_core/text/juce_CharacterFunctions.h View File

@@ -391,18 +391,28 @@ public:
dest.writeNull();
}
/** Compares two characters. */
static inline int compare (juce_wchar char1, juce_wchar char2) noexcept
{
if (int diff = static_cast<int> (char1) - static_cast<int> (char2))
return diff < 0 ? -1 : 1;
return 0;
}
/** Compares two null-terminated character strings. */
template <typename CharPointerType1, typename CharPointerType2>
static int compare (CharPointerType1 s1, CharPointerType2 s2) noexcept
{
for (;;)
{
const int c1 = (int) s1.getAndAdvance();
const int c2 = (int) s2.getAndAdvance();
const int diff = c1 - c2;
const juce_wchar c1 = s1.getAndAdvance();
if (int diff = compare (c1, s2.getAndAdvance()))
return diff;
if (diff != 0) return diff < 0 ? -1 : 1;
if (c1 == 0) break;
if (c1 == 0)
break;
}
return 0;
@@ -414,31 +424,37 @@ public:
{
while (--maxChars >= 0)
{
const int c1 = (int) s1.getAndAdvance();
const int c2 = (int) s2.getAndAdvance();
const int diff = c1 - c2;
const juce_wchar c1 = s1.getAndAdvance();
if (diff != 0) return diff < 0 ? -1 : 1;
if (c1 == 0) break;
if (int diff = compare (c1, s2.getAndAdvance()))
return diff;
if (c1 == 0)
break;
}
return 0;
}
/** Compares two characters, using a case-independant match. */
static inline int compareIgnoreCase (juce_wchar char1, juce_wchar char2) noexcept
{
return char1 != char2 ? compare (toUpperCase (char1), toUpperCase (char2)) : 0;
}
/** Compares two null-terminated character strings, using a case-independant match. */
template <typename CharPointerType1, typename CharPointerType2>
static int compareIgnoreCase (CharPointerType1 s1, CharPointerType2 s2) noexcept
{
for (;;)
{
const int c1 = (int) s1.toUpperCase();
const int c2 = (int) s2.toUpperCase();
const int diff = c1 - c2;
const juce_wchar c1 = s1.getAndAdvance();
if (diff != 0) return diff < 0 ? -1 : 1;
if (c1 == 0) break;
if (int diff = compareIgnoreCase (c1, s2.getAndAdvance()))
return diff;
++s1; ++s2;
if (c1 == 0)
break;
}
return 0;
@@ -450,14 +466,13 @@ public:
{
while (--maxChars >= 0)
{
const int c1 = (int) s1.toUpperCase();
const int c2 = (int) s2.toUpperCase();
const int diff = c1 - c2;
const juce_wchar c1 = s1.getAndAdvance();
if (diff != 0) return diff < 0 ? -1 : 1;
if (c1 == 0) break;
if (int diff = compareIgnoreCase (c1, s2.getAndAdvance()))
return diff;
++s1; ++s2;
if (c1 == 0)
break;
}
return 0;


Loading…
Cancel
Save