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

Function ReadString

code/AssetLib/MMD/MMDPmxParser.cpp:82–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80 }
81
82 std::string ReadString(std::istream *stream, uint8_t encoding)
83 {
84 int size;
85 stream->read((char*) &size, sizeof(int));
86 std::vector<char> buffer;
87 if (size == 0)
88 {
89 return std::string();
90 }
91 buffer.resize(size);
92 stream->read((char*) buffer.data(), size);
93 if (encoding == 0)
94 {
95 // UTF16 to UTF8
96 const uint16_t* sourceStart = (uint16_t*)buffer.data();
97 const unsigned int targetSize = size * 3; // enough to encode
98 char *targetStart = new char[targetSize];
99 std::memset(targetStart, 0, targetSize * sizeof(char));
100
101 utf8::utf16to8( sourceStart, sourceStart + size/2, targetStart );
102
103 std::string result(targetStart);
104 delete [] targetStart;
105 return result;
106 }
107 else
108 {
109 // the name is already UTF8
110 return std::string((const char*)buffer.data(), size);
111 }
112 }
113
114 void PmxSetting::Read(std::istream *stream)
115 {

Callers 1

ReadMethod · 0.70

Calls 4

readMethod · 0.65
utf16to8Function · 0.50
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected