1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-16 19:43:06 +01:00
Files
OpenRCT2/test/tests/helpers/StringHelpers.hpp
73 b9e677945d Replace 20XX with 2022 (#18158)
* Replace 2020 with 2022

Replace all 2020 headers with 2022

* replace other years with 2022

add missing years
2022-10-01 08:42:14 +01:00

59 lines
1.5 KiB
C++

/*****************************************************************************
* Copyright (c) 2014-2022 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <cassert>
#include <string>
#include <string_view>
inline std::string StringFromHex(std::string_view input)
{
assert((input.size() & 1) == 0);
std::string result;
result.reserve(input.size() / 2);
for (size_t i = 0; i < input.size(); i += 2)
{
auto val = std::stoi(std::string(input.substr(i, 2)), nullptr, 16);
result.push_back(val);
}
return result;
}
inline std::string NormaliseLineEndings(std::string_view input)
{
std::string result;
result.reserve(input.size());
auto ignoreNextNewLine = false;
for (auto c : input)
{
if (c == '\r')
{
ignoreNextNewLine = true;
result.push_back('\n');
}
else if (c == '\n')
{
if (ignoreNextNewLine)
{
ignoreNextNewLine = false;
}
else
{
result.push_back('\n');
}
}
else
{
ignoreNextNewLine = false;
result.push_back(c);
}
}
return result;
}