|
@@ -176,36 +176,29 @@ static void UnknownChunk(StreamReaderLE* stream, const SIBChunk& chunk)
|
|
}
|
|
}
|
|
|
|
|
|
// Reads a UTF-16LE string and returns it at UTF-8.
|
|
// Reads a UTF-16LE string and returns it at UTF-8.
|
|
-static aiString ReadString(StreamReaderLE* stream, uint32_t numWChars)
|
|
|
|
-{
|
|
|
|
- if ( 0 == numWChars ) {
|
|
|
|
|
|
+static aiString ReadString(StreamReaderLE *stream, uint32_t numWChars) {
|
|
|
|
+ if ( nullptr == stream || 0 == numWChars ) {
|
|
static const aiString empty;
|
|
static const aiString empty;
|
|
return empty;
|
|
return empty;
|
|
}
|
|
}
|
|
|
|
+
|
|
// Allocate buffers (max expansion is 1 byte -> 4 bytes for UTF-8)
|
|
// Allocate buffers (max expansion is 1 byte -> 4 bytes for UTF-8)
|
|
- //UTF16* temp = new UTF16[numWChars];
|
|
|
|
std::vector<unsigned char> str;
|
|
std::vector<unsigned char> str;
|
|
- str.reserve(numWChars * 4 + 1);
|
|
|
|
- //unsigned char* str = new unsigned char[numWChars * 4 + 1];
|
|
|
|
- uint16_t *temp = new uint16_t[numWChars];
|
|
|
|
- for (uint32_t n=0;n<numWChars;n++)
|
|
|
|
- temp[n] = stream->GetU2();
|
|
|
|
|
|
+ str.reserve( numWChars * 4 + 1 );
|
|
|
|
+ uint16_t *temp = new uint16_t[ numWChars ];
|
|
|
|
+ for ( uint32_t n = 0; n < numWChars; ++n ) {
|
|
|
|
+ temp[ n ] = stream->GetU2();
|
|
|
|
+ }
|
|
|
|
|
|
// Convert it and NUL-terminate.
|
|
// Convert it and NUL-terminate.
|
|
- //const UTF16 *start = temp, *end = temp + numWChars;
|
|
|
|
|
|
+ const uint16_t *start( temp ), *end( temp + numWChars );
|
|
|
|
+ utf8::utf16to8( start, end, back_inserter( str ) );
|
|
|
|
+ str[ str.size() - 1 ] = '\0';
|
|
|
|
|
|
- const uint16_t *start = temp, *end = temp + numWChars;
|
|
|
|
- utf8::utf16to8(start, end, back_inserter(str));
|
|
|
|
-
|
|
|
|
- //UTF8 *dest = str, *limit = str + numWChars*4;
|
|
|
|
- //ConvertUTF16toUTF8(&start, end, &dest, limit, lenientConversion);
|
|
|
|
- //*dest = '\0';
|
|
|
|
-
|
|
|
|
- str[str.size()] = '\0';
|
|
|
|
// Return the final string.
|
|
// Return the final string.
|
|
aiString result = aiString((const char *)&str[0]);
|
|
aiString result = aiString((const char *)&str[0]);
|
|
- //delete[] str;
|
|
|
|
delete[] temp;
|
|
delete[] temp;
|
|
|
|
+
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -223,26 +216,26 @@ SIBImporter::~SIBImporter() {
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
// Returns whether the class can handle the format of the given file.
|
|
// Returns whether the class can handle the format of the given file.
|
|
-bool SIBImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const
|
|
|
|
-{
|
|
|
|
|
|
+bool SIBImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const {
|
|
return SimpleExtensionCheck(pFile, "sib");
|
|
return SimpleExtensionCheck(pFile, "sib");
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-const aiImporterDesc* SIBImporter::GetInfo () const
|
|
|
|
-{
|
|
|
|
|
|
+const aiImporterDesc* SIBImporter::GetInfo () const {
|
|
return &desc;
|
|
return &desc;
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-static void ReadVerts(SIBMesh* mesh, StreamReaderLE* stream, uint32_t count)
|
|
|
|
-{
|
|
|
|
- mesh->pos.resize(count);
|
|
|
|
|
|
+static void ReadVerts(SIBMesh* mesh, StreamReaderLE* stream, uint32_t count) {
|
|
|
|
+ if ( nullptr == mesh || nullptr == stream ) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- for (uint32_t n=0;n<count;n++) {
|
|
|
|
- mesh->pos[n].x = stream->GetF4();
|
|
|
|
- mesh->pos[n].y = stream->GetF4();
|
|
|
|
- mesh->pos[n].z = stream->GetF4();
|
|
|
|
|
|
+ mesh->pos.resize(count);
|
|
|
|
+ for ( uint32_t n=0; n<count; ++n ) {
|
|
|
|
+ mesh->pos[ n ].x = stream->GetF4();
|
|
|
|
+ mesh->pos[ n ].y = stream->GetF4();
|
|
|
|
+ mesh->pos[ n ].z = stream->GetF4();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|