Browse Source

Couple of minor fixes to CharacterFunctions, and added a find-character method.

tags/2021-05-28
jules 12 years ago
parent
commit
59b9b0ccaf
4 changed files with 29 additions and 6 deletions
  1. +1
    -1
      modules/juce_core/memory/juce_MemoryBlock.cpp
  2. +1
    -0
      modules/juce_core/text/juce_CharPointer_UTF8.h
  3. +26
    -4
      modules/juce_core/text/juce_CharacterFunctions.h
  4. +1
    -1
      modules/juce_gui_basics/drawables/juce_SVGParser.cpp

+ 1
- 1
modules/juce_core/memory/juce_MemoryBlock.cpp View File

@@ -382,7 +382,7 @@ static const char base64DecodingTable[] =
bool MemoryBlock::fromBase64Encoding (StringRef s)
{
String::CharPointerType dot (CharacterFunctions::find (s.text, CharPointer_ASCII (".")));
String::CharPointerType dot (CharacterFunctions::find (s.text, (juce_wchar) '.'));
if (dot.isEmpty())
return false;


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

@@ -118,6 +118,7 @@ public:
/** Moves this pointer along to the next character in the string. */
CharPointer_UTF8& operator++() noexcept
{
jassert (*data != 0); // trying to advance past the end of the string?
const signed char n = (signed char) *data++;
if (n < 0)


+ 26
- 4
modules/juce_core/text/juce_CharacterFunctions.h View File

@@ -428,12 +428,14 @@ public:
{
for (;;)
{
const int c1 = (int) s1.toUpperCase(); ++s1;
const int c2 = (int) s2.toUpperCase(); ++s2;
const int c1 = (int) s1.toUpperCase();
const int c2 = (int) s2.toUpperCase();
const int diff = c1 - c2;
if (diff != 0) return diff < 0 ? -1 : 1;
if (c1 == 0) break;
++s1; ++s2;
}
return 0;
@@ -445,12 +447,14 @@ public:
{
while (--maxChars >= 0)
{
const int c1 = (int) s1.toUpperCase(); ++s1;
const int c2 = (int) s2.toUpperCase(); ++s2;
const int c1 = (int) s1.toUpperCase();
const int c2 = (int) s2.toUpperCase();
const int diff = c1 - c2;
if (diff != 0) return diff < 0 ? -1 : 1;
if (c1 == 0) break;
++s1; ++s2;
}
return 0;
@@ -493,6 +497,24 @@ public:
return textToSearch;
}
/** Returns a pointer to the first occurrence of a substring in a string.
If the substring is not found, this will return a pointer to the string's
null terminator.
*/
template <typename CharPointerType>
static CharPointerType find (CharPointerType textToSearch, const juce_wchar charToLookFor) noexcept
{
for (;; ++textToSearch)
{
const juce_wchar c = *textToSearch;
if (c == charToLookFor || c == 0)
break;
}
return textToSearch;
}
/** Finds the character index of a given substring in another string, using
a case-independent match.
Returns -1 if the substring is not found.


+ 1
- 1
modules/juce_gui_basics/drawables/juce_SVGParser.cpp View File

@@ -965,7 +965,7 @@ private:
if (! openBrace.isEmpty())
{
String::CharPointerType closeBrace = CharacterFunctions::find (openBrace, CharPointer_ASCII ("}"));
String::CharPointerType closeBrace = CharacterFunctions::find (openBrace, (juce_wchar) '}');
if (closeBrace != openBrace)
{


Loading…
Cancel
Save