MCPcopy Create free account
hub / github.com/MITK/MITK / ConvertFilterToRegex

Function ConvertFilterToRegex

Modules/RESTAPI/src/mitkDataStorageBridge.cpp:199–224  ·  view source on GitHub ↗

* @brief Convert a filter pattern with wildcards into a regex string. * * Escapes all regex-special characters in the literal segments and maps * wildcard characters to their regex equivalents: * - '*' -> '.*' (match zero or more characters) * - '?' -> '.' (match exactly one character) * * The result is anchored with ^ and $ for a full-string match. * * @pre filterPatte

Source from the content-addressed store, hash-verified

197 * @return A regex string that matches the same semantics.
198 */
199 std::string ConvertFilterToRegex(const std::string& filterPattern)
200 {
201 std::string regex = "^";
202
203 for (char c : filterPattern)
204 {
205 switch (c)
206 {
207 case '*': regex += ".*"; break;
208 case '?': regex += "."; break;
209 // Escape regex-special characters
210 case '.': case '+': case '(': case ')':
211 case '[': case ']': case '{': case '}':
212 case '\\': case '^': case '$': case '|':
213 regex += '\\';
214 regex += c;
215 break;
216 default:
217 regex += c;
218 break;
219 }
220 }
221
222 regex += "$";
223 return regex;
224 }
225
226 /**
227 * @brief Check if a filter pattern contains wildcard characters (* or ?).

Callers 1

MatchesPropertyFilterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected