Changeset 18736 in webkit for trunk/JavaScriptCore/wtf


Ignore:
Timestamp:
Jan 10, 2007, 1:57:56 AM (18 years ago)
Author:
lars
Message:

Use the new functionality in Qt 4.3, to make
the methods closer compliant with the Unicode
spec.

Keep the old code so that it still compiles against
Qt 4.2.

File:
1 edited

Legend:

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

    r18712 r18736  
    1 // -*- c-basic-offset: 2 -*-
    21/*
    32 *  This file is part of the KDE libraries
     
    143142    };
    144143
     144
     145#if QT_VERSION >= 0x040300
     146    // FIXME: handle surrogates correctly in all methods
     147   
     148    inline int toLower(UChar* str, int strLength, UChar*& destIfNeeded)
     149    {
     150      destIfNeeded = 0;
     151
     152      // FIXME: handle special casing. Easiest with some low level API in Qt
     153      for (int i = 0; i < strLength; ++i)
     154        str[i] = QChar::toLower(str[i]);
     155
     156      return strLength;
     157    }
     158
     159    inline UChar32 toLower(UChar32 ch)
     160    {
     161      return QChar::toLower(ch);
     162    }
     163
     164    inline int toLower(UChar* result, int resultLength, const UChar* src, int srcLength,  bool* error)
     165    {
     166      // FIXME: handle special casing. Easiest with some low level API in Qt
     167      *error = false;
     168      if (resultLength < srcLength) {
     169        *error = true;
     170        return srcLength;
     171      }
     172      for (int i = 0; i < srcLength; ++i)
     173        result[i] = QChar::toLower(src[i]);
     174    }
     175
     176    inline int toUpper(UChar* str, int strLength, UChar*& destIfNeeded)
     177    {
     178      // FIXME: handle special casing. Easiest with some low level API in Qt
     179      destIfNeeded = 0;
     180
     181      for (int i = 0; i < strLength; ++i)
     182        str[i] = QChar::toUpper(str[i]);
     183
     184      return strLength;
     185    }
     186
     187    inline UChar32 toUpper(UChar32 ch)
     188    {
     189      return QChar::toUpper(ch);
     190    }
     191
     192    inline int toUpper(UChar* result, int resultLength, UChar* src, int srcLength,  bool* error)
     193    {
     194      // FIXME: handle special casing. Easiest with some low level API in Qt
     195      *error = false;
     196      if (resultLength < srcLength) {
     197        *error = true;
     198        return srcLength;
     199      }
     200      for (int i = 0; i < srcLength; ++i)
     201        result[i] = QChar::toUpper(src[i]);
     202    }
     203
     204    inline int toTitleCase(UChar32 c)
     205    {
     206      return QChar::toTitleCase(c);
     207    }
     208
     209    inline UChar32 foldCase(UChar32 c)
     210    {
     211      return QChar::toCaseFolded(c);
     212    }
     213
     214    inline int foldCase(UChar* result, int resultLength, UChar* src, int srcLength,  bool* error)
     215    {
     216      // FIXME: handle special casing. Easiest with some low level API in Qt
     217      *error = false;
     218      if (resultLength < srcLength) {
     219        *error = true;
     220        return srcLength;
     221      }
     222      for (int i = 0; i < srcLength; ++i)
     223        result[i] = QChar::toCaseFolded(src[i]);
     224    }
     225
     226    inline bool isFormatChar(UChar32 c)
     227    {
     228      return QChar::category(c) == QChar::Other_Format;
     229    }
     230
     231    inline bool isPrintableChar(UChar32 c)
     232    {
     233      const uint test = U_MASK(QChar::Other_Control) |
     234                        U_MASK(QChar::Other_NotAssigned);
     235      return !(U_MASK(QChar::category(c)) & test);
     236    }
     237
     238    inline bool isSeparatorSpace(UChar32 c)
     239    {
     240      return QChar::category(c) == QChar::Separator_Space;
     241    }
     242
     243    inline bool isPunct(UChar32 c)
     244    {
     245      const uint test = U_MASK(QChar::Punctuation_Connector) |
     246                        U_MASK(QChar::Punctuation_Dash) |
     247                        U_MASK(QChar::Punctuation_Open) |
     248                        U_MASK(QChar::Punctuation_Close) |
     249                        U_MASK(QChar::Punctuation_InitialQuote) |
     250                        U_MASK(QChar::Punctuation_FinalQuote) |
     251                        U_MASK(QChar::Punctuation_Other);
     252      return U_MASK(QChar::category(c)) & test;
     253    }
     254
     255    inline bool isDigit(UChar32 c)
     256    {
     257      return QChar::category(c) == QChar::Number_DecimalDigit;
     258    }
     259
     260    inline bool isLower(UChar32 c)
     261    {
     262      return QChar::category(c) == QChar::Letter_Lowercase;
     263    }
     264
     265    inline bool isUpper(UChar32 c)
     266    {
     267      return QChar::category(c) == QChar::Letter_Uppercase;
     268    }
     269
     270    inline int digitValue(UChar32 c)
     271    {
     272      return QChar::digitValue(c);
     273    }
     274
     275    inline UChar32 mirroredChar(UChar32 c)
     276    {
     277      return QChar::mirroredChar(c);
     278    }
     279
     280    inline uint8_t combiningClass(UChar32 c)
     281    {
     282      return QChar::combiningClass(c);
     283    }
     284
     285    inline DecompositionType decompositionType(UChar32 c)
     286    {
     287      return (DecompositionType)QChar::decompositionTag(c);
     288    }
     289
     290    inline int umemcasecmp(const UChar* a, const UChar* b, int len)
     291    {
     292      // handle surrogates correctly
     293      for (int i = 0; i < len; ++i) {
     294        QChar c1 = QChar(a[i]).toCaseFolded();
     295        QChar c2 = QChar(b[i]).toCaseFolded();
     296        if (c1 != c2)
     297          return c1 < c2;
     298      }
     299      return 0;
     300    }
     301
     302    inline Direction direction(UChar32 c)
     303    {
     304      return (Direction)QChar::direction(c);
     305    }
     306
     307    inline CharCategory category(UChar32 c)
     308    {
     309      return (CharCategory) U_MASK(QChar::category(c));
     310    }
     311   
     312#else
     313
    145314    inline int toLower(UChar* str, int strLength, UChar*& destIfNeeded)
    146315    {
     
    292461    }
    293462
    294     inline Direction direction(UChar32 c) {
     463    inline Direction direction(UChar32 c)
     464    {
    295465      if (c > 0xffff)
    296466        return LeftToRight;
     
    298468    }
    299469
    300     inline CharCategory category(UChar32 c) {
     470    inline CharCategory category(UChar32 c)
     471    {
    301472      if (c > 0xffff)
    302473        return (CharCategory) U_MASK(QChar::Letter_Other);
     
    304475    }
    305476
     477#endif
     478   
    306479  }
    307480}
Note: See TracChangeset for help on using the changeset viewer.