Files
OpenRCT2-Web/test/tests/helpers/StringHelpers.hpp
T

26 lines
846 B
C++
Raw Normal View History

2018-06-15 14:07:34 +02:00
/*****************************************************************************
* Copyright (c) 2014-2018 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.
*****************************************************************************/
2018-04-15 16:43:28 +01:00
#include <cassert>
#include <string>
#include <string_view>
inline std::string StringFromHex(const 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)
{
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;
}