2019-09-27 22:35:57 +02:00
|
|
|
#include <std_include.hpp>
|
|
|
|
#include "string.hpp"
|
|
|
|
|
|
|
|
namespace utils::string
|
|
|
|
{
|
|
|
|
const char* va(const char* fmt, ...)
|
|
|
|
{
|
|
|
|
static thread_local va_provider<8, 256> provider;
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
const char* result = provider.get(fmt, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string to_lower(std::string text)
|
|
|
|
{
|
2022-04-10 04:04:14 +02:00
|
|
|
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
2019-09-27 22:35:57 +02:00
|
|
|
{
|
2022-04-10 04:04:14 +02:00
|
|
|
return static_cast<char>(std::tolower(input));
|
2019-09-27 22:35:57 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string to_upper(std::string text)
|
|
|
|
{
|
2022-04-10 04:04:14 +02:00
|
|
|
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
2019-09-27 22:35:57 +02:00
|
|
|
{
|
2022-04-10 04:04:14 +02:00
|
|
|
return static_cast<char>(std::toupper(input));
|
2019-09-27 22:35:57 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2022-04-25 15:26:51 +01:00
|
|
|
std::wstring convert(const std::string& str)
|
|
|
|
{
|
|
|
|
std::wstring result;
|
|
|
|
result.reserve(str.size());
|
|
|
|
|
|
|
|
for (const auto& chr : str)
|
|
|
|
{
|
|
|
|
result.push_back(static_cast<wchar_t>(chr));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-09-27 22:35:57 +02:00
|
|
|
std::string dump_hex(const std::string& data, const std::string& separator)
|
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < data.size(); ++i)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
result.append(separator);
|
|
|
|
}
|
|
|
|
|
|
|
|
result.append(va("%02X", data[i] & 0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|