Changeset 35775 in webkit for trunk/JavaScriptCore/API/JSStringRefCF.cpp
- Timestamp:
- Aug 15, 2008, 12:43:48 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSStringRefCF.cpp
r35227 r35775 30 30 #include "APICast.h" 31 31 #include "JSStringRef.h" 32 #include "OpaqueJSString.h" 32 33 #include <kjs/ustring.h> 33 34 #include <kjs/JSValue.h> 34 35 using namespace KJS; 35 #include <wtf/OwnArrayPtr.h> 36 36 37 37 JSStringRef JSStringCreateWithCFString(CFStringRef string) 38 38 { 39 39 CFIndex length = CFStringGetLength(string); 40 UString::Rep* rep; 41 if (!length) 42 rep = UString("").rep()->ref(); 43 else { 44 UniChar* buffer = static_cast<UniChar*>(fastMalloc(sizeof(UniChar) * length)); 45 CFStringGetCharacters(string, CFRangeMake(0, length), buffer); 40 if (length) { 41 OwnArrayPtr<UniChar> buffer(new UniChar[length]); 42 CFStringGetCharacters(string, CFRangeMake(0, length), buffer.get()); 46 43 COMPILE_ASSERT(sizeof(UniChar) == sizeof(UChar), unichar_and_uchar_must_be_same_size); 47 rep = UString(reinterpret_cast<UChar*>(buffer), length, false).rep()->ref(); 44 return OpaqueJSString::create(buffer.get(), length).releaseRef(); 45 } else { 46 return OpaqueJSString::create(0, 0).releaseRef(); 48 47 } 49 return toRef(rep); 50 } 48 } 51 49 52 50 CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string) 53 51 { 54 UString::Rep* rep = toJS(string); 55 return CFStringCreateWithCharacters(alloc, reinterpret_cast<const UniChar*>(rep->data()), rep->size()); 52 return CFStringCreateWithCharacters(alloc, reinterpret_cast<const UniChar*>(string->characters()), string->length()); 56 53 }
Note:
See TracChangeset
for help on using the changeset viewer.