mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 21:09:41 +00:00
Fix compile errors by using StatelessUtf8Encoder
This commit is contained in:
parent
4a06351c3b
commit
139ae9325a
3 changed files with 9 additions and 37 deletions
|
@ -38,45 +38,17 @@ namespace ESM
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::getStringImpl(std::string& str, std::size_t size,
|
bool Reader::getStringImpl(std::string& str, std::size_t size,
|
||||||
Files::IStreamPtr filestream, ToUTF8::Utf8Encoder* encoder, bool hasNull)
|
Files::IStreamPtr filestream, ToUTF8::StatelessUtf8Encoder* encoder, bool hasNull)
|
||||||
{
|
{
|
||||||
std::size_t newSize = size;
|
std::size_t newSize = size;
|
||||||
|
|
||||||
if (encoder)
|
if (encoder)
|
||||||
{
|
{
|
||||||
if (!hasNull)
|
std::string input(size, '\0');
|
||||||
newSize += 1; // Utf8Encoder::getLength() expects a null terminator
|
filestream->read(input.data(), size);
|
||||||
|
if (filestream->gcount() == static_cast<std::streamsize>(size))
|
||||||
std::string tmp;
|
|
||||||
tmp.resize(newSize);
|
|
||||||
filestream->read(&tmp[0], size);
|
|
||||||
if ((std::size_t)filestream->gcount() == size)
|
|
||||||
{
|
{
|
||||||
if (hasNull)
|
encoder->getUtf8(input, ToUTF8::BufferAllocationPolicy::FitToRequiredSize, str);
|
||||||
{
|
|
||||||
assert (tmp[newSize - 1] == '\0'
|
|
||||||
&& "ESM4::Reader::getString string is not terminated with a null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// NOTE: script text of some mods have terminating null;
|
|
||||||
// unfortunately we just have to deal with it
|
|
||||||
//if (tmp[newSize - 2] != '\0')
|
|
||||||
tmp[newSize - 1] = '\0'; // for Utf8Encoder::getLength()
|
|
||||||
}
|
|
||||||
|
|
||||||
encoder->toUtf8(tmp, str, newSize - 1);
|
|
||||||
// NOTE: the encoder converts “keep” as “keep†which increases the length,
|
|
||||||
// which results in below resize() truncating the string
|
|
||||||
if (str.size() == newSize) // ascii
|
|
||||||
str.resize(newSize - 1); // don't want the null terminator
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// this is a horrible hack but fortunately there's only a few like this
|
|
||||||
std::string tmp2(str.data());
|
|
||||||
str.swap(tmp2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace ESM
|
||||||
|
|
||||||
virtual inline bool hasMoreRecs() const = 0;
|
virtual inline bool hasMoreRecs() const = 0;
|
||||||
|
|
||||||
virtual inline void setEncoder(ToUTF8::Utf8Encoder* encoder) = 0;
|
virtual inline void setEncoder(ToUTF8::StatelessUtf8Encoder* encoder) = 0;
|
||||||
|
|
||||||
// used to check for dependencies e.g. CS::Editor::run()
|
// used to check for dependencies e.g. CS::Editor::run()
|
||||||
virtual inline const std::vector<ESM::MasterData>& getGameFiles() const = 0;
|
virtual inline const std::vector<ESM::MasterData>& getGameFiles() const = 0;
|
||||||
|
@ -53,7 +53,7 @@ namespace ESM
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool getStringImpl(std::string& str, std::size_t size,
|
bool getStringImpl(std::string& str, std::size_t size,
|
||||||
Files::IStreamPtr filestream, ToUTF8::Utf8Encoder* encoder, bool hasNull = false);
|
Files::IStreamPtr filestream, ToUTF8::StatelessUtf8Encoder* encoder, bool hasNull = false);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace ESM4 {
|
||||||
|
|
||||||
ReaderContext mCtx;
|
ReaderContext mCtx;
|
||||||
|
|
||||||
ToUTF8::Utf8Encoder* mEncoder;
|
ToUTF8::StatelessUtf8Encoder* mEncoder;
|
||||||
|
|
||||||
std::size_t mFileSize;
|
std::size_t mFileSize;
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ namespace ESM4 {
|
||||||
|
|
||||||
inline bool isEsm4() const final { return true; }
|
inline bool isEsm4() const final { return true; }
|
||||||
|
|
||||||
inline void setEncoder(ToUTF8::Utf8Encoder* encoder) final { mEncoder = encoder; };
|
inline void setEncoder(ToUTF8::StatelessUtf8Encoder* encoder) final { mEncoder = encoder; };
|
||||||
|
|
||||||
const std::vector<ESM::MasterData>& getGameFiles() const final { return mHeader.mMaster; }
|
const std::vector<ESM::MasterData>& getGameFiles() const final { return mHeader.mMaster; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue