1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-14 00:14:18 +00:00

Optimised String::unquoted()

This commit is contained in:
jules 2017-05-30 11:53:18 +01:00
parent 4397cc3701
commit 7ef3c009f6

View file

@ -1637,26 +1637,23 @@ String String::upToLastOccurrenceOf (StringRef sub,
return substring (0, includeSubString ? i + sub.length() : i);
}
static bool isQuoteCharacter (juce_wchar c) noexcept
{
return c == '"' || c == '\'';
}
bool String::isQuotedString() const
{
const juce_wchar trimmedStart = trimStart()[0];
return trimmedStart == '"'
|| trimmedStart == '\'';
return isQuoteCharacter (*text.findEndOfWhitespace());
}
String String::unquoted() const
{
const int len = length();
if (! isQuoteCharacter (*text))
return *this;
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;
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