OpenRCT2/src/openrct2/core/IStream.cpp

65 lines
1.5 KiB
C++
Raw Normal View History

2016-06-24 22:16:51 +02:00
/*****************************************************************************
2020-07-21 15:04:34 +02:00
* Copyright (c) 2014-2020 OpenRCT2 developers
2016-06-24 22:16:51 +02:00
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
2016-06-24 22:16:51 +02:00
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
2016-06-24 22:16:51 +02:00
*****************************************************************************/
#include "IStream.hpp"
2018-06-22 22:58:39 +02:00
#include "../object/Object.h"
2016-06-24 22:16:51 +02:00
#include "Memory.hpp"
#include "String.hpp"
2018-06-22 22:58:39 +02:00
#include <vector>
namespace OpenRCT2
2016-06-24 22:16:51 +02:00
{
utf8* IStream::ReadString()
2016-06-24 22:16:51 +02:00
{
std::vector<utf8> result;
2016-06-24 22:16:51 +02:00
uint8_t ch;
while ((ch = ReadValue<uint8_t>()) != 0)
{
result.push_back(ch);
}
result.push_back(0);
2016-06-24 22:16:51 +02:00
utf8* resultString = Memory::AllocateArray<utf8>(result.size());
std::copy(result.begin(), result.end(), resultString);
return resultString;
}
std::string IStream::ReadStdString()
{
std::string result;
uint8_t ch;
while ((ch = ReadValue<uint8_t>()) != 0)
{
result.push_back(ch);
}
return result;
}
void IStream::WriteString(const utf8* str)
2016-06-24 22:16:51 +02:00
{
if (str == nullptr)
{
WriteValue<uint8_t>(0);
}
else
{
size_t numBytes = String::SizeOf(str) + 1;
Write(str, numBytes);
}
2016-06-24 22:16:51 +02:00
}
void IStream::WriteString(const std::string& str)
2016-06-24 22:16:51 +02:00
{
WriteString(str.c_str());
2016-06-24 22:16:51 +02:00
}
} // namespace OpenRCT2