Returns true iff the wildcard pattern matches the string. The first ':' or '\0' character in pattern marks the end of it. This recursive algorithm isn't very efficient, but is clear and works well enough for matching test names, which are short.
| 1968 | // This recursive algorithm isn't very efficient, but is clear and |
| 1969 | // works well enough for matching test names, which are short. |
| 1970 | bool UnitTestOptions::PatternMatchesString(const char *pattern, |
| 1971 | const char *str) { |
| 1972 | switch (*pattern) { |
| 1973 | case '\0': |
| 1974 | case ':': // Either ':' or '\0' marks the end of the pattern. |
| 1975 | return *str == '\0'; |
| 1976 | case '?': // Matches any single character. |
| 1977 | return *str != '\0' && PatternMatchesString(pattern + 1, str + 1); |
| 1978 | case '*': // Matches any string (possibly empty) of characters. |
| 1979 | return (*str != '\0' && PatternMatchesString(pattern, str + 1)) || |
| 1980 | PatternMatchesString(pattern + 1, str); |
| 1981 | default: // Non-special character. Matches itself. |
| 1982 | return *pattern == *str && |
| 1983 | PatternMatchesString(pattern + 1, str + 1); |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | bool UnitTestOptions::MatchesFilter( |
| 1988 | const std::string& name, const char* filter) { |
nothing calls this directly
no outgoing calls
no test coverage detected