diff --git a/extras/the jucer/src/model/components/jucer_ComponentTypeHandler.cpp b/extras/the jucer/src/model/components/jucer_ComponentTypeHandler.cpp index e07acffb3b..8ec7f5ad7d 100644 --- a/extras/the jucer/src/model/components/jucer_ComponentTypeHandler.cpp +++ b/extras/the jucer/src/model/components/jucer_ComponentTypeHandler.cpp @@ -561,10 +561,8 @@ void ComponentTypeHandler::fillInCreationCode (GeneratedCode& code, Component* c s << "());\n"; else { - StringArray lines; - lines.addLines (params); - - params = lines.joinIntoString ("\n" + String::repeatedString (" ", s.length() + 2)); + params = StringArray::fromLines (params) + .joinIntoString ("\n" + String::repeatedString (" ", s.length() + 2)); s << " (" << params << "));\n"; } diff --git a/modules/juce_core/native/juce_linux_Network.cpp b/modules/juce_core/native/juce_linux_Network.cpp index 0dd84e8815..35dbd735aa 100644 --- a/modules/juce_core/native/juce_linux_Network.cpp +++ b/modules/juce_core/native/juce_linux_Network.cpp @@ -258,8 +258,7 @@ private: if (responseHeader.isNotEmpty()) { - headerLines.clear(); - headerLines.addLines (responseHeader); + headerLines = StringArray::fromLines (responseHeader); const int statusCode = responseHeader.fromFirstOccurrenceOf (" ", false, false) .substring (0, 3).getIntValue(); diff --git a/modules/juce_core/native/juce_posix_SharedCode.h b/modules/juce_core/native/juce_posix_SharedCode.h index 22294bb350..00b03bfe17 100644 --- a/modules/juce_core/native/juce_posix_SharedCode.h +++ b/modules/juce_core/native/juce_posix_SharedCode.h @@ -1077,9 +1077,7 @@ private: bool ChildProcess::start (const String& command) { - StringArray tokens; - tokens.addTokens (command, true); - return start (tokens); + return start (StringArray::fromTokens (command, true)); } bool ChildProcess::start (const StringArray& args) diff --git a/modules/juce_core/text/juce_StringArray.cpp b/modules/juce_core/text/juce_StringArray.cpp index 4e0856ddb2..6e294c69a5 100644 --- a/modules/juce_core/text/juce_StringArray.cpp +++ b/modules/juce_core/text/juce_StringArray.cpp @@ -418,6 +418,30 @@ int StringArray::addLines (const String& sourceText) return numLines; } +StringArray StringArray::fromTokens (const String& stringToTokenise, + bool preserveQuotedStrings) +{ + StringArray s; + s.addTokens (stringToTokenise, preserveQuotedStrings); + return s; +} + +StringArray StringArray::fromTokens (const String& stringToTokenise, + const String& breakCharacters, + const String& quoteCharacters) +{ + StringArray s; + s.addTokens (stringToTokenise, breakCharacters, quoteCharacters); + return s; +} + +StringArray StringArray::fromLines (const String& stringToBreakUp) +{ + StringArray s; + s.addLines (stringToBreakUp); + return s; +} + //============================================================================== void StringArray::removeDuplicates (const bool ignoreCase) { diff --git a/modules/juce_core/text/juce_StringArray.h b/modules/juce_core/text/juce_StringArray.h index b0cd6f6a37..bfc068fe9e 100644 --- a/modules/juce_core/text/juce_StringArray.h +++ b/modules/juce_core/text/juce_StringArray.h @@ -211,8 +211,8 @@ public: This will tokenise the given string using whitespace characters as the token delimiters, and will add these tokens to the end of the array. - @returns the number of tokens added + @see fromTokens */ int addTokens (const String& stringToTokenise, bool preserveQuotedStrings); @@ -229,6 +229,7 @@ public: which are treated as quotes. Any text occurring between quotes is not broken up into tokens. @returns the number of tokens added + @see fromTokens */ int addTokens (const String& stringToTokenise, const String& breakCharacters, @@ -242,6 +243,40 @@ public: */ int addLines (const String& stringToBreakUp); + /** Returns an array containing the tokens in a given string. + + This will tokenise the given string using whitespace characters as the + token delimiters, and return these tokens as an array. + @see addTokens + */ + static StringArray fromTokens (const String& stringToTokenise, + bool preserveQuotedStrings); + + /** Returns an array containing the tokens in a given string. + + This will tokenise the given string using whitespace characters as the + token delimiters, and return these tokens as an array. + + @param stringToTokenise the string to tokenise + @param breakCharacters a string of characters, any of which will be considered + to be a token delimiter. + @param quoteCharacters if this string isn't empty, it defines a set of characters + which are treated as quotes. Any text occurring + between quotes is not broken up into tokens. + @see addTokens + */ + static StringArray fromTokens (const String& stringToTokenise, + const String& breakCharacters, + const String& quoteCharacters); + + /** Returns an array containing the lines in a given string. + + This breaks a string down into lines separated by \\n or \\r\\n, and returns an + array containing these lines. Line-break characters are omitted from the strings that + are added to the array. + */ + static StringArray fromLines (const String& stringToBreakUp); + //============================================================================== /** Removes all elements from the array. */ void clear(); diff --git a/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp b/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp index e9e159eddb..58963f7dd0 100644 --- a/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp +++ b/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp @@ -584,9 +584,8 @@ void CodeDocument::replaceSection (const int start, const int end, const String& void CodeDocument::applyChanges (const String& newContent) { - StringArray correctedLines; - correctedLines.addLines (newContent); - const String corrected (correctedLines.joinIntoString (newLineChars)); + const String corrected (StringArray::fromLines (newContent) + .joinIntoString (newLineChars)); TextDiff diff (getAllContent(), corrected);