22 #include "ns3/assert.h"
32 const std::string& matchedPath,
33 const std::string& wildcardSeparator)
36 if (configPath ==
"*")
41 std::vector<std::string> nonWildcardTokens;
42 std::vector<std::size_t> nonWildcardTokenPositions;
44 size_t nonWildcardTokenCount;
45 size_t wildcardCount = 0;
53 tokenStart = asterisk + 1;
54 asterisk = configPath.find(
'*', tokenStart);
57 if (asterisk != std::string::npos)
63 nonWildcardTokens.push_back(configPath.substr(tokenStart, asterisk - tokenStart));
64 }
while (asterisk != std::string::npos);
67 if (wildcardCount == 0)
73 nonWildcardTokenCount = nonWildcardTokens.size();
80 for (i = 0; i < nonWildcardTokenCount; i++)
83 token = matchedPath.find(nonWildcardTokens[i], tokenStart);
86 if (token == std::string::npos)
88 NS_ASSERT_MSG(
false,
"Error: non-wildcard token not found in matched path");
92 nonWildcardTokenPositions.push_back(token);
96 tokenStart = token + nonWildcardTokens[i].size();
99 std::string wildcardMatches =
"";
104 size_t wildcardMatchesSet = 0;
107 for (i = 0; i < nonWildcardTokenCount; i++)
110 matchStart = nonWildcardTokenPositions[i] + nonWildcardTokens[i].size();
111 if (i != nonWildcardTokenCount - 1)
113 matchEnd = nonWildcardTokenPositions[i + 1] - 1;
117 matchEnd = matchedPath.length() - 1;
123 if (matchStart <= matchEnd)
126 wildcardMatches += matchedPath.substr(matchStart, matchEnd - matchStart + 1);
129 wildcardMatchesSet++;
130 if (wildcardMatchesSet == wildcardCount)
138 wildcardMatches += wildcardSeparator;
144 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...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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,...