Browse Source

Fix to a UTF-8 conversion operator for certain high value unicode points.

tags/2021-05-28
jules 10 years ago
parent
commit
449bfb852a
3 changed files with 7 additions and 20 deletions
  1. +5
    -6
      modules/juce_core/text/juce_CharPointer_UTF8.h
  2. +1
    -8
      modules/juce_core/text/juce_CharacterFunctions.h
  3. +1
    -6
      modules/juce_core/text/juce_String.cpp

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

@@ -90,9 +90,9 @@ public:
uint32 n = (uint32) (uint8) byte;
uint32 mask = 0x7f;
uint32 bit = 0x40;
size_t numExtraValues = 0;
int numExtraValues = 0;
while ((n & bit) != 0 && bit > 0x10)
while ((n & bit) != 0 && bit > 0x8)
{
mask >>= 1;
++numExtraValues;
@@ -101,9 +101,9 @@ public:
n &= mask;
for (size_t i = 1; i <= numExtraValues; ++i)
for (int i = 1; i <= numExtraValues; ++i)
{
const uint8 nextByte = (uint8) data [i];
const uint32 nextByte = (uint32) (uint8) data[i];
if ((nextByte & 0xc0) != 0x80)
break;
@@ -312,9 +312,8 @@ public:
static size_t getBytesRequiredFor (CharPointer text) noexcept
{
size_t count = 0;
juce_wchar n;
while ((n = text.getAndAdvance()) != 0)
while (juce_wchar n = text.getAndAdvance())
count += getBytesRequiredFor (n);
return count;


+ 1
- 8
modules/juce_core/text/juce_CharacterFunctions.h View File

@@ -331,15 +331,8 @@ public:
template <typename DestCharPointerType, typename SrcCharPointerType>
static void copyAll (DestCharPointerType& dest, SrcCharPointerType src) noexcept
{
for (;;)
{
const juce_wchar c = src.getAndAdvance();
if (c == 0)
break;
while (juce_wchar c = src.getAndAdvance())
dest.write (c);
}
dest.writeNull();
}


+ 1
- 6
modules/juce_core/text/juce_String.cpp View File

@@ -86,12 +86,7 @@ public:
if (text.getAddress() == nullptr || text.isEmpty())
return CharPointerType (&(emptyString.text));
CharPointer t (text);
size_t bytesNeeded = sizeof (CharType);
while (! t.isEmpty())
bytesNeeded += CharPointerType::getBytesRequiredFor (t.getAndAdvance());
const size_t bytesNeeded = sizeof (CharType) + CharPointerType::getBytesRequiredFor (text);
const CharPointerType dest (createUninitialisedBytes (bytesNeeded));
CharPointerType (dest).writeAll (text);
return dest;


Loading…
Cancel
Save