Changeset 27746 in webkit for trunk/JavaScriptCore/API


Ignore:
Timestamp:
Nov 12, 2007, 11:12:55 PM (18 years ago)
Author:
[email protected]
Message:

Reviewed by Darin.

http://bugs.webkit.org/show_bug.cgi?id=15953
Add UTF-8 encoding/decoding to WTF

  • kjs/ustring.h: Moved UTF8SequenceLength() and decodeUTF8Sequence() to wtf/unicode.
  • kjs/ustring.cpp: (KJS::UString::UTF8String): Changed this function to take a strict/lenient parameter. Callers are not interested in getting decoding results in strict mode, so this allows for bailing out as soon as an error is seen.
  • kjs/function.cpp: (KJS::encode): Updated for new UString::UTF8String() signature.
  • API/JSStringRef.cpp: (JSStringCreateWithCharacters): Disambiguate UChar. (JSStringCreateWithUTF8CString): Actually use UTF-8 when creating the string!
  • bindings/c/c_utility.cpp: (KJS::Bindings::convertUTF8ToUTF16): Use ConvertUTF8ToUTF16().
  • wtf/unicode/UTF8.cpp: Added. (WTF::Unicode::inlineUTF8SequenceLengthNonASCII): (WTF::Unicode::inlineUTF8SequenceLength): (WTF::Unicode::UTF8SequenceLength): (WTF::Unicode::decodeUTF8Sequence): (WTF::Unicode::): (WTF::Unicode::ConvertUTF16ToUTF8): (WTF::Unicode::isLegalUTF8): (WTF::Unicode::ConvertUTF8ToUTF16):
  • wtf/unicode/UTF8.h: Added. (WTF::Unicode::): Some code moved from ustring.h, some adapted from unicode.org sources.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSStringRef.cpp

    r27730 r27746  
    3737#include <kjs/ustring.h>
    3838#include <kjs/value.h>
     39#include <wtf/unicode/UTF8.h>
    3940
    4041using namespace KJS;
     42using namespace WTF::Unicode;
    4143
    4244JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars)
    4345{
    4446    JSLock lock;
    45     return toRef(UString(reinterpret_cast<const UChar*>(chars), static_cast<int>(numChars)).rep()->ref());
     47    return toRef(UString(reinterpret_cast<const KJS::UChar*>(chars), static_cast<int>(numChars)).rep()->ref());
    4648}
    4749
     
    4951{
    5052    JSLock lock;
    51     // FIXME: <rdar://problem/4949018>
    52     return toRef(UString(string).rep()->ref());
     53
     54    size_t length = strlen(string);
     55    Vector< ::UChar, 1024> buffer(length);
     56    ::UChar* p = buffer.data();
     57    ConvertUTF8ToUTF16(&string, string + length, &p, p + length, false);
     58
     59    return toRef(UString(reinterpret_cast<KJS::UChar*>(buffer.data()), p - buffer.data()).rep()->ref());
    5360}
    5461
Note: See TracChangeset for help on using the changeset viewer.