diff --git a/modules/juce_core/streams/juce_MemoryOutputStream.cpp b/modules/juce_core/streams/juce_MemoryOutputStream.cpp index adbaed2f2b..28a558570b 100644 --- a/modules/juce_core/streams/juce_MemoryOutputStream.cpp +++ b/modules/juce_core/streams/juce_MemoryOutputStream.cpp @@ -89,14 +89,14 @@ char* MemoryOutputStream::prepareToWrite (size_t numBytes) if (storageNeeded >= blockToUse->getSize()) blockToUse->ensureSize ((storageNeeded + jmin (storageNeeded / 2, (size_t) (1024 * 1024)) + 32) & ~31u); - data = static_cast (blockToUse->getData()); + data = static_cast (blockToUse->getData()); } else { if (storageNeeded > availableSize) return nullptr; - data = static_cast (externalData); + data = static_cast (externalData); } char* const writePointer = data + position; @@ -157,7 +157,7 @@ const void* MemoryOutputStream::getData() const noexcept return externalData; if (blockToUse->getSize() > size) - static_cast (blockToUse->getData()) [size] = 0; + static_cast (blockToUse->getData()) [size] = 0; return blockToUse->getData(); } @@ -194,7 +194,7 @@ int64 MemoryOutputStream::writeFromInputStream (InputStream& source, int64 maxNu String MemoryOutputStream::toUTF8() const { - const char* const d = static_cast (getData()); + const char* const d = static_cast (getData()); return String (CharPointer_UTF8 (d), CharPointer_UTF8 (d + getDataSize())); } diff --git a/modules/juce_core/text/juce_CharPointer_UTF8.h b/modules/juce_core/text/juce_CharPointer_UTF8.h index cf8e6d9be4..f6e156e147 100644 --- a/modules/juce_core/text/juce_CharPointer_UTF8.h +++ b/modules/juce_core/text/juce_CharPointer_UTF8.h @@ -458,9 +458,9 @@ public: } /** Returns true if the first character of this string is whitespace. */ - bool isWhitespace() const noexcept { return *data == ' ' || (*data <= 13 && *data >= 9); } + bool isWhitespace() const noexcept { const CharType c = *data; return c == ' ' || (c <= 13 && c >= 9); } /** Returns true if the first character of this string is a digit. */ - bool isDigit() const noexcept { return *data >= '0' && *data <= '9'; } + bool isDigit() const noexcept { const CharType c = *data; return c >= '0' && c <= '9'; } /** Returns true if the first character of this string is a letter. */ bool isLetter() const noexcept { return CharacterFunctions::isLetter (operator*()) != 0; } /** Returns true if the first character of this string is a letter or digit. */ diff --git a/modules/juce_core/xml/juce_XmlDocument.cpp b/modules/juce_core/xml/juce_XmlDocument.cpp index 2eab527a25..ecbba2df95 100644 --- a/modules/juce_core/xml/juce_XmlDocument.cpp +++ b/modules/juce_core/xml/juce_XmlDocument.cpp @@ -555,7 +555,8 @@ void XmlDocument::readChildElements (XmlElement& parent) else // must be a character block { input = preWhitespaceInput; // roll back to include the leading whitespace - String textElementContent; + MemoryOutputStream textElementContent; + bool contentShouldBeUsed = ! ignoreEmptyTextElements; for (;;) { @@ -602,28 +603,20 @@ void XmlDocument::readChildElements (XmlElement& parent) input = entity.getCharPointer(); outOfData = false; - for (;;) - { - XmlElement* const n = readNextElement (true); - - if (n == nullptr) - break; - + while (XmlElement* n = readNextElement (true)) childAppender.append (n); - } input = oldInput; outOfData = oldOutOfData; } else { - textElementContent += entity; + textElementContent << entity; + contentShouldBeUsed = contentShouldBeUsed || entity.containsNonWhitespaceChars(); } } else { - const String::CharPointerType start (input); - for (;;) { const juce_wchar nextChar = *input; @@ -638,15 +631,15 @@ void XmlDocument::readChildElements (XmlElement& parent) return; } + textElementContent.appendUTF8Char (nextChar); + contentShouldBeUsed = contentShouldBeUsed || ! CharacterFunctions::isWhitespace (nextChar); ++input; } - - textElementContent.appendCharPointer (start, input); } } - if ((! ignoreEmptyTextElements) || textElementContent.containsNonWhitespaceChars()) - childAppender.append (XmlElement::createTextElement (textElementContent)); + if (contentShouldBeUsed) + childAppender.append (XmlElement::createTextElement (textElementContent.toString())); } } }