mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add util::crop_utf8 (stringutil)
This commit is contained in:
parent
f2b9d0620a
commit
f8d0a4f4c7
3 changed files with 38 additions and 0 deletions
|
|
@ -141,6 +141,19 @@ extern uint32_t util::decode_utf8(uint& size, const char* chr) {
|
|||
return code;
|
||||
}
|
||||
|
||||
size_t util::crop_utf8(std::string_view s, size_t maxSize) {
|
||||
size_t pos = 0;
|
||||
uint size = 0;
|
||||
while (pos < s.length()) {
|
||||
decode_utf8(size, &s.at(pos));
|
||||
if (pos + size > maxSize) {
|
||||
return pos;
|
||||
}
|
||||
pos += size;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
std::string util::wstr2str_utf8(const std::wstring& ws) {
|
||||
std::vector<char> chars;
|
||||
char buffer[4];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue