mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-22 14:24:33 +01:00
Implement C++ solution to truncate UTF8 strings
This commit is contained in:
committed by
Gymnasiast
parent
645685de18
commit
0957542503
@@ -807,6 +807,22 @@ namespace String
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string_view UTF8Truncate(std::string_view v, size_t size)
|
||||
{
|
||||
auto trunc = v.substr(0, size);
|
||||
for (size_t i = 0; i < trunc.size();)
|
||||
{
|
||||
auto length = UTF8GetCodePointSize(trunc.substr(i, trunc.size()));
|
||||
if (!length.has_value())
|
||||
{
|
||||
return trunc.substr(0, i);
|
||||
}
|
||||
i += *length;
|
||||
}
|
||||
|
||||
return trunc;
|
||||
}
|
||||
} // namespace String
|
||||
|
||||
char32_t CodepointView::iterator::GetNextCodepoint(const char* ch, const char** next)
|
||||
|
||||
Reference in New Issue
Block a user