2016-06-24 22:16:51 +02:00
|
|
|
/*****************************************************************************
|
2019-03-17 08:16:15 +01:00
|
|
|
* Copyright (c) 2014-2019 OpenRCT2 developers
|
2016-06-24 22:16:51 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +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
|
|
|
*
|
2018-06-15 14:07:34 +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
|
|
|
|
2016-06-24 22:16:51 +02:00
|
|
|
#include "Memory.hpp"
|
|
|
|
#include "String.hpp"
|
|
|
|
|
2018-06-22 22:58:39 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
utf8* IStream::ReadString()
|
2016-06-24 22:16:51 +02:00
|
|
|
{
|
|
|
|
std::vector<utf8> result;
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
uint8_t ch;
|
|
|
|
while ((ch = ReadValue<uint8_t>()) != 0)
|
2016-06-24 22:16:51 +02:00
|
|
|
{
|
|
|
|
result.push_back(ch);
|
|
|
|
}
|
|
|
|
result.push_back(0);
|
|
|
|
|
2018-06-22 22:58:39 +02:00
|
|
|
utf8* resultString = Memory::AllocateArray<utf8>(result.size());
|
2018-02-01 13:52:39 +01:00
|
|
|
std::copy(result.begin(), result.end(), resultString);
|
2016-06-24 22:16:51 +02:00
|
|
|
return resultString;
|
|
|
|
}
|
|
|
|
|
2016-10-23 22:27:44 +02:00
|
|
|
std::string IStream::ReadStdString()
|
|
|
|
{
|
2018-04-14 19:06:49 +02:00
|
|
|
std::string result;
|
2018-06-20 17:28:51 +02:00
|
|
|
uint8_t ch;
|
|
|
|
while ((ch = ReadValue<uint8_t>()) != 0)
|
2016-10-23 22:27:44 +02:00
|
|
|
{
|
|
|
|
result.push_back(ch);
|
|
|
|
}
|
2018-04-14 19:06:49 +02:00
|
|
|
return result;
|
2016-10-23 22:27:44 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 22:58:39 +02:00
|
|
|
void IStream::WriteString(const utf8* str)
|
2016-06-24 22:16:51 +02:00
|
|
|
{
|
|
|
|
if (str == nullptr)
|
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
WriteValue<uint8_t>(0);
|
2016-06-24 22:16:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t numBytes = String::SizeOf(str) + 1;
|
|
|
|
Write(str, numBytes);
|
|
|
|
}
|
|
|
|
}
|
2016-10-22 19:06:52 +02:00
|
|
|
|
2018-06-22 22:58:39 +02:00
|
|
|
void IStream::WriteString(const std::string& str)
|
2016-10-22 19:06:52 +02:00
|
|
|
{
|
|
|
|
WriteString(str.c_str());
|
|
|
|
}
|