Skip to content

avoid implicit conversion of string to regExp in string-list matching

Currently have this type of code:

labelList findStrings(const std::string& re, const UList<StringType>& lst, const bool invert=false)
{
    const regExp matcher(re);
    return findMatchingStrings(matcher, lst, invert);
}

This means that the seeming innocuous call

findStrings(someWord, listOfString);

actually incurs an additional regExp allocation and then uses this for performing the match. If the word contains a '.' meta-character, this could well lead to false positives. In either case, we would be using the regex matcher when a simple string compare would also work.