58 if (isalnum(c) || c ==
'/' || c ==
'_')
66 bool validate(
const std::string& name, std::string& error)
75 if (!isalpha(c) && c !=
'/' && c !=
'~')
78 ss <<
"Character [" << c <<
"] is not valid as the first character in Graph Resource Name [" << name <<
"]. Valid characters are a-z, A-Z, / and in some cases ~.";
83 for (
size_t i = 1; i < name.size(); ++i)
89 ss <<
"Character [" << c <<
"] at element [" << i <<
"] is not valid in Graph Resource Name [" << name <<
"]. Valid characters are a-z, A-Z, 0-9, / and _.";
99 std::string
clean(
const std::string& name)
101 std::string
clean = name;
103 size_t pos = clean.find(
"//");
104 while (pos != std::string::npos)
107 pos = clean.find(
"//", pos);
110 if (*clean.rbegin() ==
'/')
112 clean.erase(clean.size() - 1, 1);
118 std::string
append(
const std::string& left,
const std::string& right)
120 return clean(left +
"/" + right);
123 std::string
remap(
const std::string& name)
125 std::string resolved =
resolve(name,
false);
127 M_string::const_iterator it = g_remappings.find(resolved);
128 if (it != g_remappings.end())
136 std::string
resolve(
const std::string& name,
bool _remap)
142 std::string
resolve(
const std::string& ns,
const std::string& name,
bool _remap)
165 std::string copy = name;
189 M_string::const_iterator it = remappings.begin();
190 M_string::const_iterator end = remappings.end();
191 for (; it != end; ++it)
193 const std::string& left = it->first;
194 const std::string& right = it->second;
198 std::string resolved_left =
resolve(left,
false);
199 std::string resolved_right =
resolve(right,
false);
200 g_remappings[resolved_left] = resolved_right;
201 g_unresolved_remappings[left] = right;
214 if (!name.compare(
""))
return "";
215 if (!name.compare(
"/"))
return "/";
217 std::string stripped_name;
220 if (name.find_last_of(
'/') == name.size()-1)
221 stripped_name = name.substr(0, name.size() -2);
223 stripped_name = name;
226 size_t last_pos = stripped_name.find_last_of(
'/');
227 if (last_pos == std::string::npos)
231 else if (last_pos == 0)
233 return stripped_name.substr(0, last_pos);
M_string g_unresolved_remappings
bool isValidCharInName(char c)
ROSCPP_DECL std::string parentNamespace(const std::string &name)
Get the parent namespace of a name.
ROSCPP_DECL const std::string & getName()
Returns the name of the current node.
ROSCPP_DECL bool validate(const std::string &name, std::string &error)
Validate a name against the name spec.
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
Resolve a graph resource name into a fully qualified graph resource name.
ROSCPP_DECL std::string clean(const std::string &name)
Cleans a graph resource name: removes double slashes, trailing slash.
ROSCPP_DECL const M_string & getRemappings()
std::map< std::string, std::string > M_string
void init(const M_string &remappings)
ROSCPP_DECL std::string remap(const std::string &name)
Apply remappings to a name.
ROSCPP_DECL const std::string & getNamespace()
Returns the namespace of the current node.
ROSCPP_DECL const M_string & getUnresolvedRemappings()
Thrown when an invalid graph resource name is specified to any roscpp function.
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
Append one name to another.