MCPcopy Create free account
hub / github.com/assimp/assimp / XMLIDEncode

Function XMLIDEncode

code/AssetLib/Collada/ColladaExporter.cpp:121–147  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------ Encodes a string into a valid XML ID using the xsd:ID schema qualifications.

Source from the content-addressed store, hash-verified

119// ------------------------------------------------------------------------------------------------
120// Encodes a string into a valid XML ID using the xsd:ID schema qualifications.
121static const std::string XMLIDEncode(const std::string &name) {
122 const char XML_ID_CHARS[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.";
123 const unsigned int XML_ID_CHARS_COUNT = sizeof(XML_ID_CHARS) / sizeof(char) - 1;
124
125 if (name.length() == 0) {
126 return name;
127 }
128
129 std::stringstream idEncoded;
130
131 // xsd:ID must start with letter or underscore
132 if (!((name[0] >= 'A' && name[0] <= 'z') || name[0] == '_')) {
133 idEncoded << '_';
134 }
135
136 for (std::string::const_iterator it = name.begin(); it != name.end(); ++it) {
137 // xsd:ID can only contain letters, digits, underscores, hyphens and periods
138 if (strchr(XML_ID_CHARS, *it) != nullptr) {
139 idEncoded << *it;
140 } else {
141 // Select placeholder character based on invalid character to reduce ID collisions
142 idEncoded << XML_ID_CHARS[(*it) % XML_ID_CHARS_COUNT];
143 }
144 }
145
146 return idEncoded.str();
147}
148
149// ------------------------------------------------------------------------------------------------
150// Helper functions to create unique ids

Callers 4

WriteFloatArrayMethod · 0.85
WriteAnimationLibraryMethod · 0.85
GetNodeUniqueIdMethod · 0.85
AddObjectIndexToMapsMethod · 0.85

Calls 3

strMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected