Adding StringPairArray - fromStringArray to JUCE?


#1

Not sure whether it makes any sense to add this to the library but I just needed something like the code below and it might be handy:

static StringPairArray fromStringArray(const StringArray& stringArray)
{
    StringPairArray spa;
    for (int i=0; i<stringArray.size(); ++i)
    {
        const String& s(stringArray[i]);
        const String key(s.upToFirstOccurrenceOf("=", false, false));
        const String val(s.fromFirstOccurrenceOf("=", false, false));
        if (key.isNotEmpty())
            spa.set(key, val);        
    }
    return spa;
}

What makes this more complicated than StringArray::fromLines() / StringArray::fromTokens() is that the “=” is fixed in this implementation and one might also consider trimming key and/or value.