mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05:38 +00:00
(Windows) Added error handling to StringUtil::stringToWideString() and StringUtil::wideStringToString() to avoid crashes caused by invalid characters.
This commit is contained in:
parent
56665af45e
commit
f550ba7dfc
|
@ -12,6 +12,7 @@
|
|||
#endif
|
||||
|
||||
#include "utils/StringUtil.h"
|
||||
#include "Log.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
|
@ -617,14 +618,28 @@ namespace Utils
|
|||
std::wstring stringToWideString(const std::string& stringArg)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> stringConverter;
|
||||
try {
|
||||
return stringConverter.from_bytes(stringArg);
|
||||
}
|
||||
catch (...) {
|
||||
LOG(LogError) << "StringUtil::stringToWideString(): Conversion failed, invalid "
|
||||
"characters in source string?";
|
||||
return L"";
|
||||
}
|
||||
}
|
||||
|
||||
std::string wideStringToString(const std::wstring& stringArg)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> stringConverter;
|
||||
try {
|
||||
return stringConverter.to_bytes(stringArg);
|
||||
}
|
||||
catch (...) {
|
||||
LOG(LogError) << "StringUtil::wideStringToString(): Conversion failed, invalid "
|
||||
"characters in source string?";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
bool startsWith(const std::string& stringArg, const std::string& start)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue