MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / validateInstanceName

Function validateInstanceName

src/xml_parsing.cpp:155–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155void validateInstanceName(const std::string& name, int line_number)
156{
157 // Instance name CAN be empty (defaults to model name)
158 // Instance names are XML attribute VALUES, so they can contain spaces,
159 // periods, and most characters. We only reject control characters that
160 // are invalid in XML.
161 if(name.empty())
162 {
163 return;
164 }
165 for(const char c : name)
166 {
167 const auto uc = static_cast<unsigned char>(c);
168 // Only reject control characters that are invalid in XML
169 // (XML allows tab=0x09, newline=0x0A, carriage return=0x0D)
170 if(uc < 32 && uc != 0x09 && uc != 0x0A && uc != 0x0D)
171 {
172 const auto line_str = std::to_string(line_number);
173 throw RuntimeError("Error at line ", line_str, ": Instance name '", name,
174 "' contains invalid control character (ASCII ",
175 std::to_string(static_cast<int>(uc)), ")");
176 }
177 if(uc == 127)
178 {
179 const auto line_str = std::to_string(line_number);
180 throw RuntimeError("Error at line ", line_str, ": Instance name '", name,
181 "' contains invalid control character (ASCII 127)");
182 }
183 }
184}
185
186struct SubtreeModel
187{

Callers 1

createNodeFromXMLMethod · 0.85

Calls 3

RuntimeErrorClass · 0.85
to_stringFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected