In fact there’s a bit of a bug in your version - not all platforms use a 16-bit value for juce_wchar, so on mac/linux it could go a bit nasty. Try this:
String result;
result.preallocateStorage (numChars + 2);
const uint16* const src = (const uint16*) (data + 2);
tchar* const dst = const_cast <tchar*> ((const tchar*) result);
if (bigEndian)
{
for (int i = 0; i < numChars; ++i)
dst[i] = (tchar) swapIfLittleEndian (src[i]);
}
else
{
for (int i = 0; i < numChars; ++i)
dst[i] = (tchar) swapIfBigEndian (src[i]);
}
dst [numChars] = 0;
return result;
}[/code]
The stuff in OutputStream is also wrong, because it makes the same assumptions about wide char size. (The fact that it’s always little-endian doesn’t make much difference, as long as the encoding is the same way round as the header bytes). I think this version should be more reliable:
[code] if (asUnicode)
{
if (writeUnicodeHeaderBytes)
write ("\x0ff\x0fe", 2);