checkpoint. fixed the other cases in the same function as the

previous checkin.  also prevented the errors flag from getting
reset after the multibyte to wide character conversion.
This commit is contained in:
crs 2002-07-23 11:51:13 +00:00
parent e93a12868d
commit 2fa9b263f9
1 changed files with 18 additions and 14 deletions

View File

@ -260,6 +260,10 @@ CUnicode::UTF8ToText(const CString& src, bool* errors)
CString CString
CUnicode::UCS2ToUTF8(const CString& src, bool* errors) CUnicode::UCS2ToUTF8(const CString& src, bool* errors)
{ {
// default to success
resetError(errors);
// convert
UInt32 n = src.size() >> 1; UInt32 n = src.size() >> 1;
return doUCS2ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors); return doUCS2ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors);
} }
@ -267,6 +271,10 @@ CUnicode::UCS2ToUTF8(const CString& src, bool* errors)
CString CString
CUnicode::UCS4ToUTF8(const CString& src, bool* errors) CUnicode::UCS4ToUTF8(const CString& src, bool* errors)
{ {
// default to success
resetError(errors);
// convert
UInt32 n = src.size() >> 2; UInt32 n = src.size() >> 2;
return doUCS4ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors); return doUCS4ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors);
} }
@ -274,6 +282,10 @@ CUnicode::UCS4ToUTF8(const CString& src, bool* errors)
CString CString
CUnicode::UTF16ToUTF8(const CString& src, bool* errors) CUnicode::UTF16ToUTF8(const CString& src, bool* errors)
{ {
// default to success
resetError(errors);
// convert
UInt32 n = src.size() >> 1; UInt32 n = src.size() >> 1;
return doUTF16ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors); return doUTF16ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors);
} }
@ -281,6 +293,10 @@ CUnicode::UTF16ToUTF8(const CString& src, bool* errors)
CString CString
CUnicode::UTF32ToUTF8(const CString& src, bool* errors) CUnicode::UTF32ToUTF8(const CString& src, bool* errors)
{ {
// default to success
resetError(errors);
// convert
UInt32 n = src.size() >> 2; UInt32 n = src.size() >> 2;
return doUTF32ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors); return doUTF32ToUTF8(reinterpret_cast<const UInt8*>(src.data()), n, errors);
} }
@ -334,13 +350,13 @@ CUnicode::textToUTF8(const CString& src, bool* errors)
for (const char* scan = src.c_str(); n > 0 && *scan != 0; ++dst) { for (const char* scan = src.c_str(); n > 0 && *scan != 0; ++dst) {
size_t mblen = mbrtowc(dst, scan, n, &state); size_t mblen = mbrtowc(dst, scan, n, &state);
switch (mblen) { switch (mblen) {
case (size_t)2: case (size_t)-2:
// incomplete character. convert to unknown character. // incomplete character. convert to unknown character.
*dst = (wchar_t)0xfffd; *dst = (wchar_t)0xfffd;
n = 0; n = 0;
break; break;
case (size_t)1: case (size_t)-1:
// invalid character. count one unknown character and // invalid character. count one unknown character and
// start at the next byte. // start at the next byte.
scan += 1; scan += 1;
@ -404,9 +420,6 @@ CUnicode::wideCharToUTF8(const wchar_t* src, bool* errors)
CString CString
CUnicode::doUCS2ToUTF8(const UInt8* data, UInt32 n, bool* errors) CUnicode::doUCS2ToUTF8(const UInt8* data, UInt32 n, bool* errors)
{ {
// default to success
resetError(errors);
// make some space // make some space
CString dst; CString dst;
dst.reserve(n); dst.reserve(n);
@ -428,9 +441,6 @@ CUnicode::doUCS2ToUTF8(const UInt8* data, UInt32 n, bool* errors)
CString CString
CUnicode::doUCS4ToUTF8(const UInt8* data, UInt32 n, bool* errors) CUnicode::doUCS4ToUTF8(const UInt8* data, UInt32 n, bool* errors)
{ {
// default to success
resetError(errors);
// make some space // make some space
CString dst; CString dst;
dst.reserve(n); dst.reserve(n);
@ -452,9 +462,6 @@ CUnicode::doUCS4ToUTF8(const UInt8* data, UInt32 n, bool* errors)
CString CString
CUnicode::doUTF16ToUTF8(const UInt8* data, UInt32 n, bool* errors) CUnicode::doUTF16ToUTF8(const UInt8* data, UInt32 n, bool* errors)
{ {
// default to success
resetError(errors);
// make some space // make some space
CString dst; CString dst;
dst.reserve(n); dst.reserve(n);
@ -502,9 +509,6 @@ CUnicode::doUTF16ToUTF8(const UInt8* data, UInt32 n, bool* errors)
CString CString
CUnicode::doUTF32ToUTF8(const UInt8* data, UInt32 n, bool* errors) CUnicode::doUTF32ToUTF8(const UInt8* data, UInt32 n, bool* errors)
{ {
// default to success
resetError(errors);
// make some space // make some space
CString dst; CString dst;
dst.reserve(n); dst.reserve(n);