- char* p = buffer;
- const UChar* d = string->characters();
- ConversionResult result = convertUTF16ToUTF8(&d, d + string->length(), &p, p + bufferSize - 1, true);
- *p++ = '\0';
+ char* destination = buffer;
+ ConversionResult result;
+ if (string->is8Bit()) {
+ const LChar* source = string->characters8();
+ result = convertLatin1ToUTF8(&source, source + string->length(), &destination, destination + bufferSize - 1);
+ } else {
+ const UChar* source = string->characters16();
+ result = convertUTF16ToUTF8(&source, source + string->length(), &destination, destination + bufferSize - 1, true);
+ }
+
+ *destination++ = '\0';