Changeset 162192 in webkit for trunk/Source/JavaScriptCore/API/JSStringRefCF.cpp
- Timestamp:
- Jan 17, 2014, 12:16:50 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSStringRefCF.cpp
r162185 r162192 41 41 // it can hold. (<rdar://problem/6806478>) 42 42 size_t length = CFStringGetLength(string); 43 if (!length) 44 return OpaqueJSString::create(reinterpret_cast<const LChar*>(""), 0).leakRef(); 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(); 45 49 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(); 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(); 56 57 } 57 58 58 CFStringRef JSStringCopyCFString(CFAllocatorRef alloc ator, JSStringRef string)59 CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string) 59 60 { 60 61 if (!string->length()) 61 62 return CFSTR(""); 62 63 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()); 64 return CFStringCreateWithCharacters(alloc, reinterpret_cast<const UniChar*>(string->deprecatedCharacters()), string->length()); 67 65 }
Note:
See TracChangeset
for help on using the changeset viewer.