Use std::out_of_range in Utf8CharSizeAt
parent
d9e26c2516
commit
550d0f915b
|
@ -156,11 +156,17 @@ std::wstring StrUtils::Utf8StringToUnicode(const std::string &str)
|
||||||
{
|
{
|
||||||
std::wstring result;
|
std::wstring result;
|
||||||
unsigned int pos = 0;
|
unsigned int pos = 0;
|
||||||
|
int len;
|
||||||
while (pos < str.size())
|
while (pos < str.size())
|
||||||
{
|
{
|
||||||
int len = StrUtils::Utf8CharSizeAt(str, pos);
|
try
|
||||||
if (len == 0)
|
{
|
||||||
|
len = StrUtils::Utf8CharSizeAt(str, pos);
|
||||||
|
}
|
||||||
|
catch (std::out_of_range &e)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
std::string ch = str.substr(pos, len);
|
std::string ch = str.substr(pos, len);
|
||||||
result += static_cast<wchar_t>(StrUtils::Utf8CharToUnicode(ch));
|
result += static_cast<wchar_t>(StrUtils::Utf8CharToUnicode(ch));
|
||||||
|
@ -172,7 +178,7 @@ std::wstring StrUtils::Utf8StringToUnicode(const std::string &str)
|
||||||
int StrUtils::Utf8CharSizeAt(const std::string &str, unsigned int pos)
|
int StrUtils::Utf8CharSizeAt(const std::string &str, unsigned int pos)
|
||||||
{
|
{
|
||||||
if (pos >= str.size())
|
if (pos >= str.size())
|
||||||
return 0;
|
throw std::out_of_range("Index is greater than size");
|
||||||
|
|
||||||
const char c = str[pos];
|
const char c = str[pos];
|
||||||
if((c & 0b1000'0000) == 0b0000'0000)
|
if((c & 0b1000'0000) == 0b0000'0000)
|
||||||
|
|
Loading…
Reference in New Issue