From 7ef3c009f67db03b1c1e752608bc99f816bdfd60 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 30 May 2017 11:53:18 +0100 Subject: [PATCH] Optimised String::unquoted() --- modules/juce_core/text/juce_String.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index 0cb5b8ad77..b67fcea45b 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -1637,26 +1637,23 @@ String String::upToLastOccurrenceOf (StringRef sub, return substring (0, includeSubString ? i + sub.length() : i); } -bool String::isQuotedString() const +static bool isQuoteCharacter (juce_wchar c) noexcept { - const juce_wchar trimmedStart = trimStart()[0]; + return c == '"' || c == '\''; +} - return trimmedStart == '"' - || trimmedStart == '\''; +bool String::isQuotedString() const +{ + return isQuoteCharacter (*text.findEndOfWhitespace()); } String String::unquoted() const { - const int len = length(); - - if (len == 0) - return {}; - - const juce_wchar lastChar = text [len - 1]; - const int dropAtStart = (*text == '"' || *text == '\'') ? 1 : 0; - const int dropAtEnd = (lastChar == '"' || lastChar == '\'') ? 1 : 0; + if (! isQuoteCharacter (*text)) + return *this; - return substring (dropAtStart, len - dropAtEnd); + auto len = length(); + return substring (1, len - (isQuoteCharacter (text[len - 1]) ? 1 : 0)); } String String::quoted (const juce_wchar quoteCharacter) const