|
|
|
@@ -171,20 +171,27 @@ bool OutputStream::writeDoubleBigEndian (double value) |
|
|
|
|
|
|
|
bool OutputStream::writeString (const String& text)
|
|
|
|
{
|
|
|
|
auto numBytes = text.getNumBytesAsUTF8() + 1;
|
|
|
|
|
|
|
|
#if (JUCE_STRING_UTF_TYPE == 8)
|
|
|
|
return write (text.toRawUTF8(), text.getNumBytesAsUTF8() + 1);
|
|
|
|
return write (text.toRawUTF8(), numBytes);
|
|
|
|
#else
|
|
|
|
// (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
|
|
|
|
// if lots of large, persistent strings were to be written to streams).
|
|
|
|
const size_t numBytes = text.getNumBytesAsUTF8() + 1;
|
|
|
|
HeapBlock<char> temp (numBytes);
|
|
|
|
text.copyToUTF8 (temp, numBytes);
|
|
|
|
return write (temp, numBytes);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OutputStream::writeText (const String& text, bool asUTF16, bool writeUTF16ByteOrderMark)
|
|
|
|
bool OutputStream::writeText (const String& text, bool asUTF16, bool writeUTF16ByteOrderMark, const char* lf)
|
|
|
|
{
|
|
|
|
bool replaceLineFeedWithUnix = lf != nullptr && lf[0] == '\n' && lf[1] == 0;
|
|
|
|
bool replaceLineFeedWithWindows = lf != nullptr && lf[0] == '\r' && lf[1] == '\n' && lf[2] == 0;
|
|
|
|
|
|
|
|
// The line-feed passed in must be either nullptr, or "\n" or "\r\n"
|
|
|
|
jassert (lf == nullptr || replaceLineFeedWithWindows || replaceLineFeedWithUnix);
|
|
|
|
|
|
|
|
if (asUTF16)
|
|
|
|
{
|
|
|
|
if (writeUTF16ByteOrderMark)
|
|
|
|
@@ -200,10 +207,17 @@ bool OutputStream::writeText (const String& text, bool asUTF16, bool writeUTF16B |
|
|
|
if (c == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (c == '\n' && ! lastCharWasReturn)
|
|
|
|
writeShort ((short) '\r');
|
|
|
|
if (replaceLineFeedWithWindows)
|
|
|
|
{
|
|
|
|
if (c == '\n' && ! lastCharWasReturn)
|
|
|
|
writeShort ((short) '\r');
|
|
|
|
|
|
|
|
lastCharWasReturn = (c == L'\r');
|
|
|
|
lastCharWasReturn = (c == L'\r');
|
|
|
|
}
|
|
|
|
else if (replaceLineFeedWithUnix && c == '\r')
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! writeShort ((short) c))
|
|
|
|
return false;
|
|
|
|
@@ -211,37 +225,57 @@ bool OutputStream::writeText (const String& text, bool asUTF16, bool writeUTF16B |
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char* src = text.toUTF8();
|
|
|
|
auto* t = src;
|
|
|
|
const char* src = text.toRawUTF8();
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
if (replaceLineFeedWithWindows)
|
|
|
|
{
|
|
|
|
if (*t == '\n')
|
|
|
|
for (auto t = src;;)
|
|
|
|
{
|
|
|
|
if (t > src)
|
|
|
|
if (! write (src, (size_t) (t - src)))
|
|
|
|
return false;
|
|
|
|
if (*t == '\n')
|
|
|
|
{
|
|
|
|
if (t > src)
|
|
|
|
if (! write (src, (size_t) (t - src)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (! write ("\r\n", 2))
|
|
|
|
return false;
|
|
|
|
if (! write ("\r\n", 2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
src = t + 1;
|
|
|
|
src = t + 1;
|
|
|
|
}
|
|
|
|
else if (*t == '\r')
|
|
|
|
{
|
|
|
|
if (t[1] == '\n')
|
|
|
|
++t;
|
|
|
|
}
|
|
|
|
else if (*t == 0)
|
|
|
|
{
|
|
|
|
if (t > src)
|
|
|
|
if (! write (src, (size_t) (t - src)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++t;
|
|
|
|
}
|
|
|
|
else if (*t == '\r')
|
|
|
|
{
|
|
|
|
if (t[1] == '\n')
|
|
|
|
++t;
|
|
|
|
}
|
|
|
|
else if (*t == 0)
|
|
|
|
}
|
|
|
|
else if (replaceLineFeedWithUnix)
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (t > src)
|
|
|
|
if (! write (src, (size_t) (t - src)))
|
|
|
|
return false;
|
|
|
|
auto c = *src++;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (c == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
++t;
|
|
|
|
if (c != '\r')
|
|
|
|
if (! writeByte (c))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return write (src, text.getNumBytesAsUTF8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -273,9 +307,9 @@ int64 OutputStream::writeFromInputStream (InputStream& source, int64 numBytesToW |
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
void OutputStream::setNewLineString (const String& newLineString_)
|
|
|
|
void OutputStream::setNewLineString (const String& newLineStringToUse)
|
|
|
|
{
|
|
|
|
newLineString = newLineString_;
|
|
|
|
newLineString = newLineStringToUse;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
|