mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
OutputStream: Fix implementation of writeText when converting to UTF-16
This commit is contained in:
parent
8b77aca786
commit
9715b901a8
1 changed files with 47 additions and 2 deletions
|
|
@ -242,7 +242,13 @@ bool OutputStream::writeText (const String& text, bool asUTF16, bool writeUTF16B
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! writeShort ((short) c))
|
CharPointer_UTF16::CharType buffer[2]{};
|
||||||
|
CharPointer_UTF16 begin { buffer };
|
||||||
|
auto end = begin;
|
||||||
|
end.write (c);
|
||||||
|
|
||||||
|
for (const auto unit : makeRange (begin.getAddress(), end.getAddress()))
|
||||||
|
if (! writeShort ((short) unit))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -403,4 +409,43 @@ JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const New
|
||||||
return stream << stream.getNewLineString();
|
return stream << stream.getNewLineString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if JUCE_UNIT_TESTS
|
||||||
|
|
||||||
|
class OutputStreamUTF16Test final : public UnitTest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OutputStreamUTF16Test() : UnitTest { "OutputStream::writeText UTF16", UnitTestCategories::streams } {}
|
||||||
|
|
||||||
|
void runTest() final
|
||||||
|
{
|
||||||
|
beginTest ("writeText UTF16 - Can support full unicode codepoints");
|
||||||
|
{
|
||||||
|
static constexpr juce_wchar stringA[] { 0x1F600, 0x00 }; // Grinning face emoji
|
||||||
|
static constexpr juce_wchar stringB[] { 0xA, 0xB, 0xC, 0x0 }; // ASCII
|
||||||
|
static constexpr juce_wchar stringC[] { 0xAAAA, 0xBBBB, 0xCCCC, 0x0 }; // two-byte characters
|
||||||
|
|
||||||
|
CharPointer_UTF32 pointers[] { CharPointer_UTF32 (stringA),
|
||||||
|
CharPointer_UTF32 (stringB),
|
||||||
|
CharPointer_UTF32 (stringC) };
|
||||||
|
|
||||||
|
for (auto originalPtr : pointers)
|
||||||
|
{
|
||||||
|
MemoryOutputStream stream;
|
||||||
|
stream.writeText (originalPtr, true, false, "\n");
|
||||||
|
|
||||||
|
expect (stream.getDataSize() != 0);
|
||||||
|
|
||||||
|
CharPointer_UTF16 writtenPtr { reinterpret_cast<const CharPointer_UTF16::CharType*> (stream.getData()) };
|
||||||
|
|
||||||
|
for (; *originalPtr != 0; ++originalPtr, ++writtenPtr)
|
||||||
|
expect (*originalPtr == *writtenPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static OutputStreamUTF16Test outputStreamUTF16Test;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace juce
|
} // namespace juce
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue