Changeset 34132 in webkit for trunk/JavaScriptCore/wtf


Ignore:
Timestamp:
May 26, 2008, 5:29:11 AM (17 years ago)
Author:
Simon Hausmann
Message:

JavaScriptCore:

2008-05-23 Tor Arne Vestbø <[email protected]>

Reviewed by Simon.

Fixed toLower and toUpper implementations to allow being called
with a null result pointer and resultLength, to determine the
number of characters needed for the case conversion.

LayoutTests:

008-05-23 Tor Arne Vestbø <[email protected]>

Reviewed by Simon.

Added a comment to the skipping of fast/css/case-transform.html that
mentions the reason of failure being a Qt bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/unicode/qt4/UnicodeQt4.h

    r33485 r34132  
    189189        const UChar *s = src;
    190190        UChar *r = result;
    191         UChar *re = result + resultLength;
     191        uint rindex = 0;
    192192
    193193        // this avoids one out of bounds check in the loop
    194         if (QChar(*s).isLowSurrogate())
    195             *r++ = *s++;
     194        if (s < e && QChar(*s).isLowSurrogate()) {
     195            if (r)
     196                r[rindex] = *s++;
     197            ++rindex;
     198        }
    196199
    197200        int needed = 0;
    198         while (s < e && r < re) {
     201        while (s < e && (rindex < resultLength || !r)) {
    199202            uint c = *s;
    200203            if (QChar(c).isLowSurrogate() && QChar(*(s - 1)).isHighSurrogate())
     
    211214                qstring = qstring.toLower();
    212215                for (int i = 0; i < qstring.length(); ++i) {
    213                     if (r == re) {
     216                    if (rindex >= resultLength) {
    214217                        needed += qstring.length() - i;
    215218                        break;
    216219                    }
    217                     *r = qstring.at(i).unicode();
    218                     ++r;
     220                    if (r)
     221                        r[rindex] = qstring.at(i).unicode();
     222                    ++rindex;
    219223                }
    220224            } else {
    221                 *r = *s + prop->lowerCaseDiff;
    222                 ++r;
     225                if (r)
     226                    r[rindex] = *s + prop->lowerCaseDiff;
     227                ++rindex;
    223228            }
    224229            ++s;
     
    227232            needed += e - s;
    228233        *error = (needed != 0);
    229         if (r < re)
    230             *r = 0;
    231         return (r - result) + needed;
     234        if (rindex < resultLength)
     235            r[rindex] = 0;
     236        return rindex + needed;
    232237    }
    233238
     
    242247        const UChar *s = src;
    243248        UChar *r = result;
    244         UChar *re = result + resultLength;
     249        int rindex = 0;
    245250
    246251        // this avoids one out of bounds check in the loop
    247         if (QChar(*s).isLowSurrogate())
    248             *r++ = *s++;
     252        if (s < e && QChar(*s).isLowSurrogate()) {
     253            if (r)
     254                r[rindex] = *s++;
     255            ++rindex;
     256        }
    249257
    250258        int needed = 0;
    251         while (s < e && r < re) {
     259        while (s < e && (rindex < resultLength || !r)) {
    252260            uint c = *s;
    253261            if (QChar(c).isLowSurrogate() && QChar(*(s - 1)).isHighSurrogate())
     
    264272                qstring = qstring.toUpper();
    265273                for (int i = 0; i < qstring.length(); ++i) {
    266                     if (r == re) {
     274                    if (rindex >= resultLength) {
    267275                        needed += qstring.length() - i;
    268276                        break;
    269277                    }
    270                     *r = qstring.at(i).unicode();
    271                     ++r;
     278                    if (r)
     279                        r[rindex] = qstring.at(i).unicode();
     280                    ++rindex;
    272281                }
    273282            } else {
    274                 *r = *s + prop->upperCaseDiff;
    275                 ++r;
     283                if (r)
     284                    r[rindex] = *s + prop->upperCaseDiff;
     285                ++rindex;
    276286            }
    277287            ++s;
     
    280290            needed += e - s;
    281291        *error = (needed != 0);
    282         if (r < re)
    283             *r = 0;
    284         return (r - result) + needed;
     292        if (rindex < resultLength)
     293            r[rindex] = 0;
     294        return rindex + needed;
    285295    }
    286296
Note: See TracChangeset for help on using the changeset viewer.