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

Function ReadString

code/AssetLib/SIB/SIBImporter.cpp:174–197  ·  view source on GitHub ↗

Reads a UTF-16LE string and returns it at UTF-8.

Source from the content-addressed store, hash-verified

172
173// Reads a UTF-16LE string and returns it at UTF-8.
174static aiString ReadString(StreamReaderLE *stream, uint32_t numWChars) {
175 if (nullptr == stream || 0 == numWChars) {
176 return aiString();
177 }
178
179 // Allocate buffers (max expansion is 1 byte -> 4 bytes for UTF-8)
180 std::vector<unsigned char> str;
181 str.reserve(numWChars * 4 + 1);
182 uint16_t *temp = new uint16_t[numWChars];
183 for (uint32_t n = 0; n < numWChars; ++n) {
184 temp[n] = stream->GetU2();
185 }
186
187 // Convert it and NUL-terminate.
188 const uint16_t *start(temp), *end(temp + numWChars);
189 utf8::utf16to8(start, end, back_inserter(str));
190 str[str.size() - 1] = '\0';
191
192 // Return the final string.
193 aiString result = aiString((const char *)&str[0]);
194 delete[] temp;
195
196 return result;
197}
198
199// ------------------------------------------------------------------------------------------------
200// Returns whether the class can handle the format of the given file.

Callers 8

ReadShapeFunction · 0.70
ReadMaterialFunction · 0.70
ReadLightFunction · 0.70
ReadInstanceFunction · 0.70
CreateMeshMethod · 0.50
ReadTEXSMethod · 0.50
ReadBRUSMethod · 0.50
ReadNODEMethod · 0.50

Calls 5

aiStringClass · 0.50
utf16to8Function · 0.50
reserveMethod · 0.45
GetU2Method · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected