Skip to content

Commit

Permalink
[runtime/fix] fix locale wstring conversion error (#1921)
Browse files Browse the repository at this point in the history
  • Loading branch information
robin1001 authored Jul 21, 2023
1 parent f97c460 commit a247e18
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions runtime/core/utils/string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,17 @@ std::string ProcessBlank(const std::string& str, bool lowercase) {
}
// NOTE: convert string to wstring
// see issue 745: https://github.com/wenet-e2e/wenet/issues/745
std::locale loc("");
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
std::wstring wsresult = converter.from_bytes(result);
for (auto& c : wsresult) {
c = lowercase ? tolower(c, loc) : toupper(c, loc);
try {
std::locale loc("");
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
std::wstring wsresult = converter.from_bytes(result);
for (auto& c : wsresult) {
c = lowercase ? tolower(c, loc) : toupper(c, loc);
}
result = converter.to_bytes(wsresult);
} catch (std::exception& e) {
LOG(ERROR) << "convert wstring error " << e.what();
}
result = converter.to_bytes(wsresult);
}
return result;
}
Expand Down

0 comments on commit a247e18

Please sign in to comment.