1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-31 18:31:04 +00:00

Various random code cleanups

This commit is contained in:
sfan5 2025-03-01 11:53:37 +01:00
parent 358658fa34
commit 7892541383
73 changed files with 216 additions and 285 deletions

View file

@ -139,16 +139,6 @@ std::string wide_to_utf8(std::wstring_view input)
return out;
}
void wide_add_codepoint(std::wstring &result, char32_t codepoint)
{
if ((0xD800 <= codepoint && codepoint <= 0xDFFF) || (0x10FFFF < codepoint)) {
// Invalid codepoint, replace with unicode replacement character
result.push_back(0xFFFD);
return;
}
result.push_back(codepoint);
}
#else // _WIN32
std::wstring utf8_to_wide(std::string_view input)
@ -175,32 +165,25 @@ std::string wide_to_utf8(std::wstring_view input)
return out;
}
#endif // _WIN32
void wide_add_codepoint(std::wstring &result, char32_t codepoint)
{
if (codepoint < 0x10000) {
if (0xD800 <= codepoint && codepoint <= 0xDFFF) {
// Invalid codepoint, part of a surrogate pair
// Replace with unicode replacement character
result.push_back(0xFFFD);
return;
}
result.push_back((wchar_t) codepoint);
return;
}
codepoint -= 0x10000;
if (codepoint >= 0x100000) {
// original codepoint was above 0x10FFFF, so invalid
// replace with unicode replacement character
if ((0xD800 <= codepoint && codepoint <= 0xDFFF) || codepoint > 0x10FFFF) {
// Invalid codepoint, replace with unicode replacement character
result.push_back(0xFFFD);
return;
}
result.push_back((wchar_t) ((codepoint >> 10) | 0xD800));
result.push_back((wchar_t) ((codepoint & 0x3FF) | 0xDC00));
if constexpr (sizeof(wchar_t) == 2) { // Surrogate encoding needed?
if (codepoint > 0xffff) {
result.push_back((wchar_t) ((codepoint >> 10) | 0xD800));
result.push_back((wchar_t) ((codepoint & 0x3FF) | 0xDC00));
return;
}
}
result.push_back((wchar_t) codepoint);
}
#endif // _WIN32
std::string urlencode(std::string_view str)
{
// Encodes reserved URI characters by a percent sign