Changeset 13170 in webkit
- Timestamp:
- Mar 6, 2006 11:59:09 AM (18 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 2 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r13158 r13170 1 2006-03-06 David Carson <dacarson@gmail.com> 2 3 Reviewed by Darin, landed by ap. 4 5 - Fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=7582 6 c_utility.cpp contains CFString OS X platform-dependent code; should use ICU 7 8 Tested with test case from: 9 http://bugzilla.opendarwin.org/show_bug.cgi?id=5163 10 11 * bindings/c_utility.cpp 12 (convertUTF8ToUTF16): Changed to using Unicode converter from ICU, and manual Latin-1 conversion. 13 * icu/unicode/ucnv.h: Copied from WebCore. 14 * icu/unicode/ucnv_err.h: Ditto. 15 * icu/unicode/uenum.h: Ditto. 16 1 17 2006-03-05 Darin Adler <darin@apple.com> 2 18 -
trunk/JavaScriptCore/bindings/c/c_utility.cpp
r13015 r13170 27 27 #include "config.h" 28 28 #include "c_utility.h" 29 #include <unicode/ucnv.h> 29 30 30 31 #include "JSType.h" … … 46 47 { 47 48 assert(UTF8Chars || UTF8Length == 0); 49 assert(UTF16Chars); 48 50 49 51 if (UTF8Length == -1) 50 52 UTF8Length = strlen(UTF8Chars); 51 52 CFStringRef stringRef = CFStringCreateWithBytes(NULL, (const UInt8*)UTF8Chars, (CFIndex)UTF8Length, kCFStringEncodingUTF8, false); 53 53 54 // UTF16Length maximum length is the length of the UTF8 string, plus one to include terminator 55 // Without the plus one, it will convert ok, but a warning is generated from the converter as 56 // there is not enough room for a terminating character. 57 *UTF16Length = UTF8Length + 1; 58 59 *UTF16Chars = 0; 60 UErrorCode status = U_ZERO_ERROR; 61 UConverter* conv = ucnv_open("utf8", &status); 62 if (U_SUCCESS(status)) { 63 *UTF16Chars = (NPUTF16 *)malloc(sizeof(NPUTF16) * (*UTF16Length)); 64 ucnv_setToUCallBack(conv, UCNV_TO_U_CALLBACK_STOP, 0, 0, 0, &status); 65 ucnv_toUChars(conv, *UTF16Chars, *UTF16Length, UTF8Chars, UTF8Length, &status); 66 ucnv_close(conv); 67 } 68 69 // Check to see if the conversion was successful 54 70 // Some plugins return invalid UTF-8 in NPVariantType_String, see <http://bugzilla.opendarwin.org/show_bug.cgi?id=5163> 55 if (!stringRef) 56 stringRef = CFStringCreateWithBytes(NULL, (const UInt8*)UTF8Chars, (CFIndex)UTF8Length, kCFStringEncodingISOLatin1, false); 57 58 // There is no "bad data" for kCFStringEncodingISOLatin1. It is unlikely that the plugin was really sending text in this encoding, 71 // There is no "bad data" for latin1. It is unlikely that the plugin was really sending text in this encoding, 59 72 // but it should have used UTF-8, and now we are simply avoiding a crash. 60 assert(stringRef); 61 62 *UTF16Length = (unsigned int)CFStringGetLength(stringRef); 63 *UTF16Chars = (NPUTF16 *)malloc(sizeof(NPUTF16) * (*UTF16Length)); 64 65 // Convert the string to UTF16. 66 CFRange range = { 0, *UTF16Length }; 67 CFStringGetCharacters(stringRef, range, (UniChar *)*UTF16Chars); 68 CFRelease(stringRef); 73 if (!U_SUCCESS(status)) { 74 if (!*UTF16Chars) // If the memory wasn't allocated, allocate it. 75 *UTF16Chars = (NPUTF16 *)malloc(sizeof(NPUTF16) * (*UTF16Length)); 76 77 for (unsigned i = 0; i < *UTF16Length; i++) 78 (*UTF16Chars)[i] = UTF8Chars[i] & 0xFF; 79 80 } 69 81 } 70 82
Note: See TracChangeset
for help on using the changeset viewer.