Skip to content

Commit

Permalink
fix(utils/string): add try-catch for wstring_converter
Browse files Browse the repository at this point in the history
Fix issue #745
  • Loading branch information
xingchensong authored Jul 21, 2023
1 parent f97c460 commit 13d9600
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 13d9600

Please sign in to comment.