Files

60 lines
1.5 KiB
C++
Raw Permalink Normal View History

2018-06-15 14:07:34 +02:00
/*****************************************************************************
2024-12-31 20:30:04 +01:00
* Copyright (c) 2014-2025 OpenRCT2 developers
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
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2026-01-15 11:11:12 -03:00
#pragma once
2018-04-15 16:43:28 +01:00
#include <cassert>
#include <string>
#include <string_view>
2021-01-07 01:22:22 +09:00
inline std::string StringFromHex(std::string_view input)
2018-04-15 16:43:28 +01:00
{
assert((input.size() & 1) == 0);
std::string result;
result.reserve(input.size() / 2);
for (size_t i = 0; i < input.size(); i += 2)
{
2018-07-25 22:49:20 +02:00
auto val = std::stoi(std::string(input.substr(i, 2)), nullptr, 16);
2018-04-15 16:43:28 +01:00
result.push_back(val);
}
return result;
}
2020-02-02 15:35:41 +00:00
2021-01-07 01:22:22 +09:00
inline std::string NormaliseLineEndings(std::string_view input)
2020-02-02 15:35:41 +00:00
{
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;
}