mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-18 19:23:56 +00:00
Merge remote-tracking branch 'origin/main' into multi-platform-support
# Conflicts: # src/analyzer/main.cpp # src/emulator/memory_region.hpp # src/windows-emulator/io_device.cpp # src/windows-emulator/module/module_mapping.cpp # src/windows-emulator/process_context.hpp # src/windows-emulator/syscalls.cpp # src/windows-emulator/windows_emulator.cpp
This commit is contained in:
50
src/common/utils/string.hpp
Normal file
50
src/common/utils/string.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <ranges>
|
||||
#include <cwctype>
|
||||
#include <algorithm>
|
||||
|
||||
namespace utils::string
|
||||
{
|
||||
inline char char_to_lower(const char val)
|
||||
{
|
||||
return static_cast<char>(std::tolower(static_cast<unsigned char>(val)));
|
||||
}
|
||||
|
||||
inline char16_t char_to_lower(const char16_t val)
|
||||
{
|
||||
if (val >= u'A' && val <= u'Z')
|
||||
{
|
||||
return val + 32;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
inline wchar_t char_to_lower(const wchar_t val)
|
||||
{
|
||||
return std::towlower(val);
|
||||
}
|
||||
|
||||
template <class Elem, class Traits, class Alloc>
|
||||
void to_lower_inplace(std::basic_string<Elem, Traits, Alloc>& str)
|
||||
{
|
||||
std::ranges::transform(str, str.begin(), [](const Elem e)
|
||||
{
|
||||
return char_to_lower(e);
|
||||
});
|
||||
}
|
||||
|
||||
template <class Elem, class Traits, class Alloc>
|
||||
std::basic_string<Elem, Traits, Alloc> to_lower(std::basic_string<Elem, Traits, Alloc> str)
|
||||
{
|
||||
to_lower_inplace(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
template <class Elem, class Traits, class Alloc>
|
||||
std::basic_string<Elem, Traits, Alloc> to_lower_consume(std::basic_string<Elem, Traits, Alloc>& str)
|
||||
{
|
||||
return to_lower(std::move(str));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user