| 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 | { |