Decode invalid utf-8 more gracefully (invalid bytes becomes U+FFFD)

This was SVN commit r6999.
This commit is contained in:
Ykkrosh
2009-07-16 15:52:18 +00:00
parent 271823cf7e
commit fcf9db0d53
3 changed files with 23 additions and 12 deletions
+8 -4
View File
@@ -156,13 +156,17 @@ CStrW CStr8::FromUTF8() const
unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
if (source + extraBytesToRead >= sourceEnd)
{
//debug_warn("Invalid UTF-8 (fell off end)");
return L"";
// Error - fell of the the end of the string
result += (wchar_t)0xFFFD;
source++;
continue;
}
if (! isLegalUTF8(source, extraBytesToRead+1)) {
//debug_warn("Invalid UTF-8 (illegal data)");
return L"";
// Error - illegal data
result += (wchar_t)0xFFFD;
source++;
continue;
}
switch (extraBytesToRead)