24 #include "ns3/assert.h"
30 const std::string &matchedPath,
31 const std::string &wildcardSeparator)
34 if (configPath ==
"*")
39 std::vector<std::string> nonWildcardTokens;
40 std::vector<std::size_t> nonWildcardTokenPositions;
42 size_t nonWildcardTokenCount;
43 size_t wildcardCount = 0;
51 tokenStart = asterisk + 1;
52 asterisk = configPath.find (
"*", tokenStart);
55 if (asterisk != std::string::npos)
61 nonWildcardTokens.push_back (configPath.substr (tokenStart, asterisk - tokenStart));
63 while (asterisk != std::string::npos);
66 if (wildcardCount == 0)
72 nonWildcardTokenCount = nonWildcardTokens.size ();
79 for (i = 0; i < nonWildcardTokenCount; i++)
82 token = matchedPath.find (nonWildcardTokens[i], tokenStart);
85 if (token == std::string::npos)
87 NS_ASSERT_MSG (
false,
"Error: non-wildcard token not found in matched path");
91 nonWildcardTokenPositions.push_back (token);
95 tokenStart = token + nonWildcardTokens[i].size ();
98 std::string wildcardMatches =
"";
103 size_t wildcardMatchesSet = 0;
106 for (i = 0; i < nonWildcardTokenCount; i++)
109 matchStart = nonWildcardTokenPositions[i] + nonWildcardTokens[i].size ();
110 if (i != nonWildcardTokenCount - 1)
112 matchEnd = nonWildcardTokenPositions[i + 1] - 1;
116 matchEnd = matchedPath.length () - 1;
122 if (matchStart <= matchEnd)
125 wildcardMatches += matchedPath.substr (matchStart,
126 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,...