|
|
@ -281,28 +281,28 @@ int u8_read_escape_sequence(const char *str, u32 *dest)
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
digs[dno++] = str[i++];
|
|
|
|
digs[dno++] = str[i++];
|
|
|
|
} while (octal_digit(str[i]) && dno < 3);
|
|
|
|
} while (octal_digit(str[i]) && dno < 3);
|
|
|
|
ch = strtol(digs, NULL, 8);
|
|
|
|
ch = strtol(digs, nullptr, 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (str[0] == 'x') {
|
|
|
|
else if (str[0] == 'x') {
|
|
|
|
while (hex_digit(str[i]) && dno < 2) {
|
|
|
|
while (hex_digit(str[i]) && dno < 2) {
|
|
|
|
digs[dno++] = str[i++];
|
|
|
|
digs[dno++] = str[i++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dno > 0)
|
|
|
|
if (dno > 0)
|
|
|
|
ch = strtol(digs, NULL, 16);
|
|
|
|
ch = strtol(digs, nullptr, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (str[0] == 'u') {
|
|
|
|
else if (str[0] == 'u') {
|
|
|
|
while (hex_digit(str[i]) && dno < 4) {
|
|
|
|
while (hex_digit(str[i]) && dno < 4) {
|
|
|
|
digs[dno++] = str[i++];
|
|
|
|
digs[dno++] = str[i++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dno > 0)
|
|
|
|
if (dno > 0)
|
|
|
|
ch = strtol(digs, NULL, 16);
|
|
|
|
ch = strtol(digs, nullptr, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (str[0] == 'U') {
|
|
|
|
else if (str[0] == 'U') {
|
|
|
|
while (hex_digit(str[i]) && dno < 8) {
|
|
|
|
while (hex_digit(str[i]) && dno < 8) {
|
|
|
|
digs[dno++] = str[i++];
|
|
|
|
digs[dno++] = str[i++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dno > 0)
|
|
|
|
if (dno > 0)
|
|
|
|
ch = strtol(digs, NULL, 16);
|
|
|
|
ch = strtol(digs, nullptr, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*dest = ch;
|
|
|
|
*dest = ch;
|
|
|
|
|
|
|
|
|
|
|
@ -353,7 +353,7 @@ const char *u8_strchr(const char *s, u32 ch, int *charn)
|
|
|
|
lasti = i;
|
|
|
|
lasti = i;
|
|
|
|
(*charn)++;
|
|
|
|
(*charn)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *u8_memchr(const char *s, u32 ch, size_t sz, int *charn)
|
|
|
|
const char *u8_memchr(const char *s, u32 ch, size_t sz, int *charn)
|
|
|
@ -378,7 +378,7 @@ const char *u8_memchr(const char *s, u32 ch, size_t sz, int *charn)
|
|
|
|
lasti = i;
|
|
|
|
lasti = i;
|
|
|
|
(*charn)++;
|
|
|
|
(*charn)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int u8_is_locale_utf8(const char *locale)
|
|
|
|
int u8_is_locale_utf8(const char *locale)
|
|
|
@ -419,35 +419,35 @@ bool UTF8StringHasNonASCII(const char *utf8string) {
|
|
|
|
|
|
|
|
|
|
|
|
std::string ConvertWStringToUTF8(const wchar_t *wstr) {
|
|
|
|
std::string ConvertWStringToUTF8(const wchar_t *wstr) {
|
|
|
|
int len = (int)wcslen(wstr);
|
|
|
|
int len = (int)wcslen(wstr);
|
|
|
|
int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr, len, 0, 0, NULL, NULL);
|
|
|
|
int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr, len, 0, 0, nullptr, nullptr);
|
|
|
|
std::string s;
|
|
|
|
std::string s;
|
|
|
|
s.resize(size);
|
|
|
|
s.resize(size);
|
|
|
|
if (size > 0) {
|
|
|
|
if (size > 0) {
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wstr, len, &s[0], size, NULL, NULL);
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wstr, len, &s[0], size, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string ConvertWStringToUTF8(const std::wstring &wstr) {
|
|
|
|
std::string ConvertWStringToUTF8(const std::wstring &wstr) {
|
|
|
|
int len = (int)wstr.size();
|
|
|
|
int len = (int)wstr.size();
|
|
|
|
int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, 0, 0, NULL, NULL);
|
|
|
|
int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, 0, 0, nullptr, nullptr);
|
|
|
|
std::string s;
|
|
|
|
std::string s;
|
|
|
|
s.resize(size);
|
|
|
|
s.resize(size);
|
|
|
|
if (size > 0) {
|
|
|
|
if (size > 0) {
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, &s[0], size, NULL, NULL);
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, &s[0], size, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source) {
|
|
|
|
void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source) {
|
|
|
|
int len = (int)source.size();
|
|
|
|
int len = (int)source.size();
|
|
|
|
int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, NULL, 0);
|
|
|
|
int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, nullptr, 0);
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, dest, std::min((int)destSize, size));
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, dest, std::min((int)destSize, size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::wstring ConvertUTF8ToWString(const std::string &source) {
|
|
|
|
std::wstring ConvertUTF8ToWString(const std::string &source) {
|
|
|
|
int len = (int)source.size();
|
|
|
|
int len = (int)source.size();
|
|
|
|
int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, NULL, 0);
|
|
|
|
int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, nullptr, 0);
|
|
|
|
std::wstring str;
|
|
|
|
std::wstring str;
|
|
|
|
str.resize(size);
|
|
|
|
str.resize(size);
|
|
|
|
if (size > 0) {
|
|
|
|
if (size > 0) {
|
|
|
|