Commit 4ad71207 authored by eric@webkit.org's avatar eric@webkit.org

2010-05-27 Luiz Agostini <luiz.agostini@openbossa.org>

        Reviewed by Darin Adler.

        UTF-16 code points compare() for String objects
        https://bugs.webkit.org/show_bug.cgi?id=39701

        Moving compare() implementation from UString to StringImpl for it to be shared
        with String. Adding overloaded free functions codePointCompare() in StringImpl
        and WTFString. Renaming function compare in UString to codePointCompare to be
        consistent.

        * runtime/JSArray.cpp:
        (JSC::compareByStringPairForQSort):
        * runtime/UString.cpp:
        * runtime/UString.h:
        (JSC::codePointCompare):
        * wtf/text/StringImpl.cpp:
        (WebCore::codePointCompare):
        * wtf/text/StringImpl.h:
        * wtf/text/WTFString.cpp:
        (WebCore::codePointCompare):
        * wtf/text/WTFString.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@60332 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 19587223
2010-05-27 Luiz Agostini <luiz.agostini@openbossa.org>
Reviewed by Darin Adler.
UTF-16 code points compare() for String objects
https://bugs.webkit.org/show_bug.cgi?id=39701
Moving compare() implementation from UString to StringImpl for it to be shared
with String. Adding overloaded free functions codePointCompare() in StringImpl
and WTFString. Renaming function compare in UString to codePointCompare to be
consistent.
* runtime/JSArray.cpp:
(JSC::compareByStringPairForQSort):
* runtime/UString.cpp:
* runtime/UString.h:
(JSC::codePointCompare):
* wtf/text/StringImpl.cpp:
(WebCore::codePointCompare):
* wtf/text/StringImpl.h:
* wtf/text/WTFString.cpp:
(WebCore::codePointCompare):
* wtf/text/WTFString.h:
2010-05-26 Darin Adler <darin@apple.com>
Reviewed by Kent Tamura.
......
......@@ -649,7 +649,7 @@ static int compareByStringPairForQSort(const void* a, const void* b)
{
const ValueStringPair* va = static_cast<const ValueStringPair*>(a);
const ValueStringPair* vb = static_cast<const ValueStringPair*>(b);
return compare(va->second, vb->second);
return codePointCompare(va->second, vb->second);
}
void JSArray::sortNumeric(ExecState* exec, JSValue compareFunction, CallType callType, const CallData& callData)
......
......@@ -580,29 +580,6 @@ bool operator>(const UString& s1, const UString& s2)
return (l1 > l2);
}
int compare(const UString& s1, const UString& s2)
{
const unsigned l1 = s1.size();
const unsigned l2 = s2.size();
const unsigned lmin = l1 < l2 ? l1 : l2;
const UChar* c1 = s1.data();
const UChar* c2 = s2.data();
unsigned l = 0;
while (l < lmin && *c1 == *c2) {
c1++;
c2++;
l++;
}
if (l < lmin)
return (c1[0] > c2[0]) ? 1 : -1;
if (l1 == l2)
return 0;
return (l1 > l2) ? 1 : -1;
}
CString UString::UTF8String(bool strict) const
{
// Allocate a buffer big enough to hold all the characters.
......
......@@ -202,7 +202,10 @@ namespace JSC {
return !JSC::operator==(s1, s2);
}
int compare(const UString&, const UString&);
inline int codePointCompare(const UString& s1, const UString& s2)
{
return codePointCompare(s1.rep(), s2.rep());
}
// Rule from ECMA 15.2 about what an array index is.
// Must exactly match string form of an unsigned integer, and be less than 2^32 - 1.
......
......@@ -476,6 +476,29 @@ static inline bool equalIgnoringCase(const UChar* a, const UChar* b, int length)
return umemcasecmp(a, b, length) == 0;
}
int codePointCompare(const StringImpl* s1, const StringImpl* s2)
{
const unsigned l1 = s1 ? s1->length() : 0;
const unsigned l2 = s2 ? s2->length() : 0;
const unsigned lmin = l1 < l2 ? l1 : l2;
const UChar* c1 = s1 ? s1->characters() : 0;
const UChar* c2 = s2 ? s2->characters() : 0;
unsigned pos = 0;
while (pos < lmin && *c1 == *c2) {
c1++;
c2++;
pos++;
}
if (pos < lmin)
return (c1[0] > c2[0]) ? 1 : -1;
if (l1 == l2)
return 0;
return (l1 > l2) ? 1 : -1;
}
int StringImpl::find(const char* chs, int index, bool caseSensitive)
{
if (!chs || index < 0)
......
......@@ -352,6 +352,8 @@ inline bool equalIgnoringCase(const char* a, const UChar* b, unsigned length) {
bool equalIgnoringNullity(StringImpl*, StringImpl*);
int codePointCompare(const StringImpl*, const StringImpl*);
static inline bool isSpaceOrNewline(UChar c)
{
// Use isASCIISpace() for basic Latin-1.
......
......@@ -126,6 +126,11 @@ String operator+(const char* cs, const String& s)
return String(cs) + s;
}
int codePointCompare(const String& a, const String& b)
{
return codePointCompare(a.impl(), b.impl());
}
void String::insert(const String& str, unsigned pos)
{
if (str.isEmpty()) {
......
......@@ -351,6 +351,8 @@ inline bool charactersAreAllASCII(const UChar* characters, size_t length)
return !(ored & 0xFF80);
}
int codePointCompare(const String&, const String&);
inline int find(const UChar* characters, size_t length, UChar character, int startPosition)
{
if (startPosition >= static_cast<int>(length))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment