21 const std::string& matchedPath,
22 const std::string& wildcardSeparator)
25 if (configPath ==
"*")
30 std::vector<std::string> nonWildcardTokens;
31 std::vector<std::size_t> nonWildcardTokenPositions;
33 size_t nonWildcardTokenCount;
34 size_t wildcardCount = 0;
42 tokenStart = asterisk + 1;
43 asterisk = configPath.find(
'*', tokenStart);
46 if (asterisk != std::string::npos)
52 nonWildcardTokens.push_back(configPath.substr(tokenStart, asterisk - tokenStart));
53 }
while (asterisk != std::string::npos);
56 if (wildcardCount == 0)
62 nonWildcardTokenCount = nonWildcardTokens.size();
69 for (i = 0; i < nonWildcardTokenCount; i++)
72 token = matchedPath.find(nonWildcardTokens[i], tokenStart);
75 if (token == std::string::npos)
77 NS_ASSERT_MSG(
false,
"Error: non-wildcard token not found in matched path");
81 nonWildcardTokenPositions.push_back(token);
85 tokenStart = token + nonWildcardTokens[i].size();
88 std::string wildcardMatches =
"";
93 size_t wildcardMatchesSet = 0;
96 for (i = 0; i < nonWildcardTokenCount; i++)
99 matchStart = nonWildcardTokenPositions[i] + nonWildcardTokens[i].size();
100 if (i != nonWildcardTokenCount - 1)
102 matchEnd = nonWildcardTokenPositions[i + 1] - 1;
106 matchEnd = matchedPath.length() - 1;
112 if (matchStart <= matchEnd)
115 wildcardMatches += matchedPath.substr(matchStart, matchEnd - matchStart + 1);
118 wildcardMatchesSet++;
119 if (wildcardMatchesSet == wildcardCount)
127 wildcardMatches += wildcardSeparator;
133 return wildcardMatches;
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
std::string GetWildcardMatches(const std::string &configPath, const std::string &matchedPath, const std::string &wildcardSeparator)
Returns the text matches from the matched path for each of the wildcards in the Config path,...