Did this already come up? I thought somebody else already posted about this, but I couldn’t find the thread. This makes it much faster.
[code] // assume it’s 16-bit unicode
const bool bigEndian = (data[0] == (char)-2);
const int numChars = size / 2 - 1;
const uint16* const src = (const uint16*) (data + 2);
uint16* dst = new uint16[numChars];
if (bigEndian)
{
for (int i = 0; i < numChars; i++)
dst[i] = (juce_wchar)swapIfLittleEndian(src[i]);
}
else
{
for (int i = 0; i < numChars; i++)
dst[i] = (juce_wchar)swapIfBigEndian(src[i]);
}
String result((juce_wchar*)dst, numChars);
delete[] dst;
return result;[/code]
Also, shouldn’t this be the other way around for big endian?
if (writeUnicodeHeaderBytes)
write ("\x0ff\x0fe", 2);