8size_t utf8_step(
unsigned char c)
12 if ((
c & 0xE0) == 0xC0)
14 if ((
c & 0xF0) == 0xE0)
16 if ((
c & 0xF8) == 0xF0)
26 for (
size_t i = 0; i <
s.size();)
28 const size_t step = utf8_step(
static_cast<unsigned char>(
s[i]));
29 if (i +
step >
s.size())
41 while (i <
s.size() &&
n < codepoints)
43 const size_t step = utf8_step(
static_cast<unsigned char>(
s[i]));
44 if (i +
step >
s.size())
52#ifdef EVENGINE_WINDOWS
54std::string to_utf8(LPCWSTR wstr)
56 size_t wide_len = wcslen(wstr)+1;
59 int utf8_size = WideCharToMultiByte(CP_UTF8, 0, wstr, wide_len, 0, 0, 0, 0);
61 char *utf8_str =
new char[utf8_size];
64 int ok = WideCharToMultiByte(CP_UTF8, 0, wstr, wide_len, utf8_str, utf8_size, 0, 0);
74std::wstring to_widestr(
const std::string &str)
77 return std::wstring();
79 int wide_size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (
int) str.length(),
nullptr, 0);
82 return std::wstring();
85 widestr.resize(wide_size);
87 int ok = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (
int) str.length(), &widestr[0], widestr.length());
90 return std::wstring();
95void replace_char(std::string &str,
char find,
char replace)
97 int length = str.length();
99 for (
int i = 0; i<length; i++)
size_t utf8_codepoint_count(const std::string &s)
Count UTF-8 code points in a string. Invalid / truncated sequences stop the scan.
size_t utf8_byte_offset_for_codepoints(const std::string &s, size_t codepoints)
Byte offset of the N-th UTF-8 code point (0-based count of code points). Returns s....