mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-14 02:10:06 +00:00
Fix U16toU8() returning strings longer than max
UTF-16 inputs containing actual multi-byte characters resulted in codecvt returning a UTF-8 string longer than the requested max length.
This commit is contained in:
parent
70c3650ee1
commit
57e9834786
@ -155,7 +155,12 @@ std::string U16toU8(char16_t* src, size_t max) {
|
||||
src[max-1] = '\0'; // force a NULL terminatorstd::string U16toU8(char16_t* src) {
|
||||
try {
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
|
||||
return convert.to_bytes(src);
|
||||
std::string ret = convert.to_bytes(src);
|
||||
|
||||
if (ret.size() >= max)
|
||||
ret.resize(max-2);
|
||||
|
||||
return ret;
|
||||
} catch(const std::exception& e) {
|
||||
return "";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user