Browse Source

Introjucer: made the string literal tool break long strings across multiple lines.

tags/2021-05-28
jules 12 years ago
parent
commit
7850bebd47
3 changed files with 27 additions and 7 deletions
  1. +25
    -5
      extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp
  2. +1
    -1
      extras/Introjucer/Source/Utility/jucer_CodeHelpers.h
  3. +1
    -1
      extras/Introjucer/Source/Utility/jucer_MiscUtilities.cpp

+ 25
- 5
extras/Introjucer/Source/Utility/jucer_CodeHelpers.cpp View File

@@ -213,15 +213,35 @@ namespace CodeHelpers
false, true, false);
}
String stringLiteral (const String& text)
String stringLiteral (const String& text, int maxLineLength)
{
if (text.isEmpty())
return "String::empty";
if (CharPointer_ASCII::isValidString (text.toUTF8(), std::numeric_limits<int>::max()))
return CodeHelpers::addEscapeChars (text).quoted();
else
return "CharPointer_UTF8 (" + CodeHelpers::addEscapeChars (text).quoted() + ")";
StringArray lines;
lines.add (text);
if (maxLineLength > 0)
{
while (lines [lines.size() - 1].length() > maxLineLength)
{
String& lastLine = lines.getReference (lines.size() - 1);
const String start (lastLine.substring (0, maxLineLength));
const String end (lastLine.substring (maxLineLength));
lastLine = start;
lines.add (end);
}
}
for (int i = 0; i < lines.size(); ++i)
lines.getReference(i) = "\"" + addEscapeChars (lines.getReference(i)) + "\"";
String result (lines.joinIntoString (newLine));
if (! CharPointer_ASCII::isValidString (text.toUTF8(), std::numeric_limits<int>::max()))
result = "CharPointer_UTF8 (" + result + ")";
return result;
}
String alignFunctionCallParams (const String& call, const StringArray& parameters, const int maxLineLength)


+ 1
- 1
extras/Introjucer/Source/Utility/jucer_CodeHelpers.h View File

@@ -38,7 +38,7 @@ namespace CodeHelpers
String makeHeaderGuardName (const File& file);
String makeBinaryDataIdentifierName (const File& file);
String stringLiteral (const String& text);
String stringLiteral (const String& text, int maxLineLength = -1);
String colourToCode (const Colour& col);
String alignFunctionCallParams (const String& call, const StringArray& parameters, int maxLineLength);


+ 1
- 1
extras/Introjucer/Source/Utility/jucer_MiscUtilities.cpp View File

@@ -357,7 +357,7 @@ public:
void update()
{
getLastText() = userText.getText();
resultText.setText (CodeHelpers::stringLiteral (getLastText()), false);
resultText.setText (CodeHelpers::stringLiteral (getLastText(), 100), false);
}
void resized()


Loading…
Cancel
Save