Changeset 18354 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Dec 20, 2006, 12:11:47 PM (18 years ago)
Author:
andersca
Message:

Reviewed by Darin.

<rdar://problem/4235733>
<http://bugs.webkit.org/?show_bug.cgi?id=10193>
support String.localeCompare.


Implement localeCompare.


  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/string_object.cpp: (localeCompare): (StringProtoFunc::callAsFunction):
  • kjs/string_object.h: (KJS::StringProtoFunc::):
Location:
trunk/JavaScriptCore/kjs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r17372 r18354  
    3131#include "regexp_object.h"
    3232#include <wtf/unicode/Unicode.h>
     33
     34#if PLATFORM(CF)
     35#include <CoreFoundation/CoreFoundation.h>
     36#endif
    3337
    3438using namespace KJS;
     
    126130  toLocaleLowerCase     StringProtoFunc::ToLocaleLowerCase DontEnum|Function    0
    127131  toLocaleUpperCase     StringProtoFunc::ToLocaleUpperCase DontEnum|Function    0
     132  localeCompare         StringProtoFunc::LocaleCompare  DontEnum|Function       1
    128133#
    129134# Under here: html extension, should only exist if KJS_PURE_ECMA is not defined
     
    277282  return substitutedReplacement;
    278283}
     284
     285#if PLATFORM(WIN_OS)
     286static inline int localeCompare(const UString& a, const UString& b)
     287{
     288    return CompareStringW(LOCALE_USER_DEFAULT, 0,
     289                          a.data(), a.length(),
     290                          b.data(), b.length());
     291}
     292#elif PLATFORM(CF)
     293static inline int localeCompare(const UString& a, const UString& b)
     294{
     295    CFStringRef sa = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(a.data()), a.size(), kCFAllocatorNull);
     296    CFStringRef sb = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(b.data()), b.size(), kCFAllocatorNull);
     297   
     298    int retval = CFStringCompare(sa, sb, kCFCompareLocalized);
     299   
     300    CFRelease(sa);
     301    CFRelease(sb);
     302   
     303    return retval;
     304}
     305#else
     306static inline int localeCompare(const UString& a, const UString& b)
     307{
     308    return compare(a, b);
     309}
     310#endif
    279311
    280312static JSValue *replace(ExecState *exec, const UString &source, JSValue *pattern, JSValue *replacement)
     
    675707    break;
    676708  }
     709  case LocaleCompare:
     710    return jsNumber(localeCompare(s, a0->toString(exec)));
    677711#ifndef KJS_PURE_ECMA
    678712  case Big:
  • trunk/JavaScriptCore/kjs/string_object.h

    r15846 r18354  
    8484           Match, Replace, Search, Slice, Split,
    8585           Substr, Substring, FromCharCode, ToLowerCase, ToUpperCase,
    86            ToLocaleLowerCase, ToLocaleUpperCase
     86           ToLocaleLowerCase, ToLocaleUpperCase, LocaleCompare
    8787#ifndef KJS_PURE_ECMA
    8888           , Big, Small, Blink, Bold, Fixed, Italics, Strike, Sub, Sup,
Note: See TracChangeset for help on using the changeset viewer.