Changeset 162205 in webkit for trunk/Source/JavaScriptCore/API/JSStringRefCF.cpp
- Timestamp:
- Jan 17, 2014, 9:44:49 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSStringRefCF.cpp
r162192 r162205 41 41 // it can hold. (<rdar://problem/6806478>) 42 42 size_t length = CFStringGetLength(string); 43 if (length) { 44 Vector<LChar, 1024> lcharBuffer(length); 45 CFIndex usedBufferLength; 46 CFIndex convertedSize = CFStringGetBytes(string, CFRangeMake(0, length), kCFStringEncodingISOLatin1, 0, false, lcharBuffer.data(), length, &usedBufferLength); 47 if (static_cast<size_t>(convertedSize) == length && static_cast<size_t>(usedBufferLength) == length) 48 return OpaqueJSString::create(lcharBuffer.data(), length).leakRef(); 43 if (!length) 44 return OpaqueJSString::create(reinterpret_cast<const LChar*>(""), 0).leakRef(); 49 45 50 auto buffer = std::make_unique<UniChar[]>(length); 51 CFStringGetCharacters(string, CFRangeMake(0, length), buffer.get()); 52 COMPILE_ASSERT(sizeof(UniChar) == sizeof(UChar), unichar_and_uchar_must_be_same_size); 53 return OpaqueJSString::create(reinterpret_cast<UChar*>(buffer.get()), length).leakRef(); 54 } 55 56 return OpaqueJSString::create(reinterpret_cast<const LChar*>(""), 0).leakRef(); 46 Vector<LChar, 1024> lcharBuffer(length); 47 CFIndex usedBufferLength; 48 CFIndex convertedSize = CFStringGetBytes(string, CFRangeMake(0, length), kCFStringEncodingISOLatin1, 0, false, lcharBuffer.data(), length, &usedBufferLength); 49 if (static_cast<size_t>(convertedSize) == length && static_cast<size_t>(usedBufferLength) == length) 50 return OpaqueJSString::create(lcharBuffer.data(), length).leakRef(); 51 52 auto buffer = std::make_unique<UniChar[]>(length); 53 CFStringGetCharacters(string, CFRangeMake(0, length), buffer.get()); 54 static_assert(sizeof(UniChar) == sizeof(UChar), "UniChar and UChar must be same size"); 55 return OpaqueJSString::create(reinterpret_cast<UChar*>(buffer.get()), length).leakRef(); 57 56 } 58 57 59 CFStringRef JSStringCopyCFString(CFAllocatorRef alloc , JSStringRef string)58 CFStringRef JSStringCopyCFString(CFAllocatorRef allocator, JSStringRef string) 60 59 { 61 60 if (!string->length()) 62 61 return CFSTR(""); 63 62 64 return CFStringCreateWithCharacters(alloc, reinterpret_cast<const UniChar*>(string->deprecatedCharacters()), string->length()); 63 if (string->is8Bit()) 64 return CFStringCreateWithBytes(allocator, reinterpret_cast<const UInt8*>(string->characters8()), string->length(), kCFStringEncodingISOLatin1, false); 65 66 return CFStringCreateWithCharacters(allocator, reinterpret_cast<const UniChar*>(string->characters16()), string->length()); 65 67 }
Note:
See TracChangeset
for help on using the changeset viewer.