X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/ba379fdc102753d6be2c4d937058fe40257329fe..14957cd040308e3eeec43d26bae5d76da13fcd85:/wtf/unicode/qt4/UnicodeQt4.h diff --git a/wtf/unicode/qt4/UnicodeQt4.h b/wtf/unicode/qt4/UnicodeQt4.h index 1531694..eaa7a07 100644 --- a/wtf/unicode/qt4/UnicodeQt4.h +++ b/wtf/unicode/qt4/UnicodeQt4.h @@ -23,14 +23,18 @@ #ifndef WTF_UNICODE_QT4_H #define WTF_UNICODE_QT4_H +#include "UnicodeMacrosFromICU.h" + #include #include #include #include +#if USE(QT_ICU_TEXT_BREAKING) +#include +#endif -#if QT_VERSION >= 0x040300 QT_BEGIN_NAMESPACE namespace QUnicodeTables { struct Properties { @@ -55,55 +59,17 @@ namespace QUnicodeTables { Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2); } QT_END_NAMESPACE -#endif // ugly hack to make UChar compatible with JSChar in API/JSStringRef.h -#if defined(Q_OS_WIN) +#if defined(Q_OS_WIN) || COMPILER(WINSCW) || (COMPILER(RVCT) && !OS(LINUX)) typedef wchar_t UChar; #else typedef uint16_t UChar; #endif -typedef uint32_t UChar32; -// some defines from ICU - -#define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800) -#define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00) -#define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) -#define U16_GET_SUPPLEMENTARY(lead, trail) \ - (((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET) - -#define U16_LEAD(supplementary) (UChar)(((supplementary)>>10)+0xd7c0) -#define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00) - -#define U_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800) -#define U16_IS_SINGLE(c) !U_IS_SURROGATE(c) -#define U16_IS_SURROGATE(c) U_IS_SURROGATE(c) -#define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0) - -#define U16_NEXT(s, i, length, c) { \ - (c)=(s)[(i)++]; \ - if(U16_IS_LEAD(c)) { \ - uint16_t __c2; \ - if((i)<(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \ - ++(i); \ - (c)=U16_GET_SUPPLEMENTARY((c), __c2); \ - } \ - } \ -} - -#define U16_PREV(s, start, i, c) { \ - (c)=(s)[--(i)]; \ - if(U16_IS_TRAIL(c)) { \ - uint16_t __c2; \ - if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \ - --(i); \ - (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \ - } \ - } \ -} - -#define U_MASK(x) ((uint32_t)1<<(x)) +#if !USE(QT_ICU_TEXT_BREAKING) +typedef uint32_t UChar32; +#endif namespace WTF { namespace Unicode { @@ -186,13 +152,11 @@ enum CharCategory { }; -#if QT_VERSION >= 0x040300 - // FIXME: handle surrogates correctly in all methods inline UChar32 toLower(UChar32 ch) { - return QChar::toLower(ch); + return QChar::toLower(uint32_t(ch)); } inline int toLower(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) @@ -248,9 +212,9 @@ inline int toLower(UChar* result, int resultLength, const UChar* src, int srcLen return rindex + needed; } -inline UChar32 toUpper(UChar32 ch) +inline UChar32 toUpper(UChar32 c) { - return QChar::toUpper(ch); + return QChar::toUpper(uint32_t(c)); } inline int toUpper(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) @@ -308,12 +272,12 @@ inline int toUpper(UChar* result, int resultLength, const UChar* src, int srcLen inline int toTitleCase(UChar32 c) { - return QChar::toTitleCase(c); + return QChar::toTitleCase(uint32_t(c)); } inline UChar32 foldCase(UChar32 c) { - return QChar::toCaseFolded(c); + return QChar::toCaseFolded(uint32_t(c)); } inline int foldCase(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) @@ -338,12 +302,12 @@ inline bool isPrintableChar(UChar32 c) { const uint test = U_MASK(QChar::Other_Control) | U_MASK(QChar::Other_NotAssigned); - return !(U_MASK(QChar::category(c)) & test); + return !(U_MASK(QChar::category(uint32_t(c))) & test); } inline bool isSeparatorSpace(UChar32 c) { - return QChar::category(c) == QChar::Separator_Space; + return QChar::category(uint32_t(c)) == QChar::Separator_Space; } inline bool isPunct(UChar32 c) @@ -355,12 +319,12 @@ inline bool isPunct(UChar32 c) U_MASK(QChar::Punctuation_InitialQuote) | U_MASK(QChar::Punctuation_FinalQuote) | U_MASK(QChar::Punctuation_Other); - return U_MASK(QChar::category(c)) & test; + return U_MASK(QChar::category(uint32_t(c))) & test; } inline bool isLower(UChar32 c) { - return QChar::category(c) == QChar::Letter_Lowercase; + return QChar::category(uint32_t(c)) == QChar::Letter_Lowercase; } inline bool hasLineBreakingPropertyComplexContext(UChar32) @@ -371,12 +335,12 @@ inline bool hasLineBreakingPropertyComplexContext(UChar32) inline UChar32 mirroredChar(UChar32 c) { - return QChar::mirroredChar(c); + return QChar::mirroredChar(uint32_t(c)); } inline uint8_t combiningClass(UChar32 c) { - return QChar::combiningClass(c); + return QChar::combiningClass(uint32_t(c)); } inline DecompositionType decompositionType(UChar32 c) @@ -398,146 +362,14 @@ inline int umemcasecmp(const UChar* a, const UChar* b, int len) inline Direction direction(UChar32 c) { - return (Direction)QChar::direction(c); + return (Direction)QChar::direction(uint32_t(c)); } inline CharCategory category(UChar32 c) { - return (CharCategory) U_MASK(QChar::category(c)); -} - -#else - -inline UChar32 toLower(UChar32 ch) -{ - if (ch > 0xffff) - return ch; - return QChar((unsigned short)ch).toLower().unicode(); -} - -inline int toLower(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) -{ - *error = false; - if (resultLength < srcLength) { - *error = true; - return srcLength; - } - for (int i = 0; i < srcLength; ++i) - result[i] = QChar(src[i]).toLower().unicode(); - return srcLength; -} - -inline UChar32 toUpper(UChar32 ch) -{ - if (ch > 0xffff) - return ch; - return QChar((unsigned short)ch).toUpper().unicode(); + return (CharCategory) U_MASK(QChar::category(uint32_t(c))); } -inline int toUpper(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) -{ - *error = false; - if (resultLength < srcLength) { - *error = true; - return srcLength; - } - for (int i = 0; i < srcLength; ++i) - result[i] = QChar(src[i]).toUpper().unicode(); - return srcLength; -} - -inline int toTitleCase(UChar32 c) -{ - if (c > 0xffff) - return c; - return QChar((unsigned short)c).toUpper().unicode(); -} - -inline UChar32 foldCase(UChar32 c) -{ - if (c > 0xffff) - return c; - return QChar((unsigned short)c).toLower().unicode(); -} - -inline int foldCase(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) -{ - return toLower(result, resultLength, src, srcLength, error); -} - -inline bool isPrintableChar(UChar32 c) -{ - return (c & 0xffff0000) == 0 && QChar((unsigned short)c).isPrint(); -} - -inline bool isArabicChar(UChar32 c) -{ - return c >= 0x0600 && c <= 0x06FF; -} - -inline bool isSeparatorSpace(UChar32 c) -{ - return (c & 0xffff0000) == 0 && QChar((unsigned short)c).category() == QChar::Separator_Space; -} - -inline bool isPunct(UChar32 c) -{ - return (c & 0xffff0000) == 0 && QChar((unsigned short)c).isPunct(); -} - -inline bool isLower(UChar32 c) -{ - return (c & 0xffff0000) == 0 && QChar((unsigned short)c).category() == QChar::Letter_Lowercase; -} - -inline UChar32 mirroredChar(UChar32 c) -{ - if (c > 0xffff) - return c; - return QChar(c).mirroredChar().unicode(); -} - -inline uint8_t combiningClass(UChar32 c) -{ - if (c > 0xffff) - return 0; - return QChar((unsigned short)c).combiningClass(); -} - -inline DecompositionType decompositionType(UChar32 c) -{ - if (c > 0xffff) - return DecompositionNone; - return (DecompositionType)QChar(c).decompositionTag(); -} - -inline int umemcasecmp(const UChar* a, const UChar* b, int len) -{ - for (int i = 0; i < len; ++i) { - QChar c1 = QChar(a[i]).toLower(); - QChar c2 = QChar(b[i]).toLower(); - if (c1 != c2) - return c1.unicode() - c2.unicode(); - } - return 0; -} - -inline Direction direction(UChar32 c) -{ - if (c > 0xffff) - return LeftToRight; - return (Direction)QChar(c).direction(); -} - -inline CharCategory category(UChar32 c) -{ - if (c > 0xffff) - return NoCategory; - return (CharCategory) U_MASK(QChar(c).category()); -} - -#endif - } } #endif // WTF_UNICODE_QT4_H