mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-20 01:14:20 +00:00
Moved some C++ escaping functions from the Introjucer into CppTokeniserFunctions.
This commit is contained in:
parent
3bb7e7ebf1
commit
c8bf8cd41e
7 changed files with 111 additions and 93 deletions
|
|
@ -102,87 +102,6 @@ namespace CodeHelpers
|
|||
return n;
|
||||
}
|
||||
|
||||
static void writeEscapeChars (OutputStream& out, const char* utf8, const int numBytes,
|
||||
const int maxCharsOnLine, const bool breakAtNewLines,
|
||||
const bool replaceSingleQuotes, const bool allowStringBreaks)
|
||||
{
|
||||
int charsOnLine = 0;
|
||||
bool lastWasHexEscapeCode = false;
|
||||
|
||||
for (int i = 0; i < numBytes || numBytes < 0; ++i)
|
||||
{
|
||||
const unsigned char c = (unsigned char) utf8[i];
|
||||
bool startNewLine = false;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '\t': out << "\\t"; lastWasHexEscapeCode = false; charsOnLine += 2; break;
|
||||
case '\r': out << "\\r"; lastWasHexEscapeCode = false; charsOnLine += 2; break;
|
||||
case '\n': out << "\\n"; lastWasHexEscapeCode = false; charsOnLine += 2; startNewLine = breakAtNewLines; break;
|
||||
case '\\': out << "\\\\"; lastWasHexEscapeCode = false; charsOnLine += 2; break;
|
||||
case '\"': out << "\\\""; lastWasHexEscapeCode = false; charsOnLine += 2; break;
|
||||
|
||||
case 0:
|
||||
if (numBytes < 0)
|
||||
return;
|
||||
|
||||
out << "\\0";
|
||||
lastWasHexEscapeCode = true;
|
||||
charsOnLine += 2;
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
if (replaceSingleQuotes)
|
||||
{
|
||||
out << "\\\'";
|
||||
lastWasHexEscapeCode = false;
|
||||
charsOnLine += 2;
|
||||
break;
|
||||
}
|
||||
|
||||
// deliberate fall-through...
|
||||
|
||||
default:
|
||||
if (c >= 32 && c < 127 && ! (lastWasHexEscapeCode // (have to avoid following a hex escape sequence with a valid hex digit)
|
||||
&& CharacterFunctions::getHexDigitValue (c) >= 0))
|
||||
{
|
||||
out << (char) c;
|
||||
lastWasHexEscapeCode = false;
|
||||
++charsOnLine;
|
||||
}
|
||||
else if (allowStringBreaks && lastWasHexEscapeCode && c >= 32 && c < 127)
|
||||
{
|
||||
out << "\"\"" << (char) c;
|
||||
lastWasHexEscapeCode = false;
|
||||
charsOnLine += 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
out << (c < 16 ? "\\x0" : "\\x") << String::toHexString ((int) c);
|
||||
lastWasHexEscapeCode = true;
|
||||
charsOnLine += 4;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ((startNewLine || (maxCharsOnLine > 0 && charsOnLine >= maxCharsOnLine))
|
||||
&& (numBytes < 0 || i < numBytes - 1))
|
||||
{
|
||||
charsOnLine = 0;
|
||||
out << "\"" << newLine << "\"";
|
||||
lastWasHexEscapeCode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String addEscapeChars (const String& s)
|
||||
{
|
||||
MemoryOutputStream out;
|
||||
writeEscapeChars (out, s.toRawUTF8(), -1, -1, false, true, true);
|
||||
return out.toUTF8();
|
||||
}
|
||||
|
||||
String createIncludeStatement (const File& includeFile, const File& targetFile)
|
||||
{
|
||||
return createIncludeStatement (FileHelpers::unixStylePath (FileHelpers::getRelativePathFrom (includeFile, targetFile.getParentDirectory())));
|
||||
|
|
@ -258,7 +177,7 @@ namespace CodeHelpers
|
|||
}
|
||||
|
||||
for (int i = 0; i < lines.size(); ++i)
|
||||
lines.getReference(i) = addEscapeChars (lines.getReference(i));
|
||||
lines.getReference(i) = CppTokeniserFunctions::addEscapeChars (lines.getReference(i));
|
||||
|
||||
lines.removeEmptyStrings();
|
||||
|
||||
|
|
@ -424,8 +343,8 @@ namespace CodeHelpers
|
|||
else
|
||||
{
|
||||
out << "\"";
|
||||
writeEscapeChars (out, (const char*) data, (int) mb.getSize(),
|
||||
maxCharsOnLine, breakAtNewLines, false, allowStringBreaks);
|
||||
CppTokeniserFunctions::writeEscapeChars (out, (const char*) data, (int) mb.getSize(),
|
||||
maxCharsOnLine, breakAtNewLines, false, allowStringBreaks);
|
||||
out << "\";";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue