| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qunicodetools.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | __attribute__((visibility("default"))) int qt_initcharattributes_default_algorithm_only = 0; | - | ||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | namespace QUnicodeTools { | - | ||||||||||||||||||
| 11 | namespace GB { | - | ||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | static const uchar breakTable[QUnicodeTables::GraphemeBreak_LVT + 1][QUnicodeTables::GraphemeBreak_LVT + 1] = { | - | ||||||||||||||||||
| 14 | - | |||||||||||||||||||
| 15 | { true , true , true , true , false, true , true , false, true , true , true , true , true }, | - | ||||||||||||||||||
| 16 | { true , true , false, true , true , true , true , true , true , true , true , true , true }, | - | ||||||||||||||||||
| 17 | { true , true , true , true , true , true , true , true , true , true , true , true , true }, | - | ||||||||||||||||||
| 18 | { true , true , true , true , true , true , true , true , true , true , true , true , true }, | - | ||||||||||||||||||
| 19 | { true , true , true , true , false, true , true , false, true , true , true , true , true }, | - | ||||||||||||||||||
| 20 | { true , true , true , true , false, false, true , false, true , true , true , true , true }, | - | ||||||||||||||||||
| 21 | { false, true , true , true , false, false, false, false, false, false, false, false, false }, | - | ||||||||||||||||||
| 22 | { true , true , true , true , false, true , true , false, true , true , true , true , true }, | - | ||||||||||||||||||
| 23 | { true , true , true , true , false, true , true , false, false, false, true , false, false }, | - | ||||||||||||||||||
| 24 | { true , true , true , true , false, true , true , false, true , false, false, true , true }, | - | ||||||||||||||||||
| 25 | { true , true , true , true , false, true , true , false, true , true , false, true , true }, | - | ||||||||||||||||||
| 26 | { true , true , true , true , false, true , true , false, true , false, false, true , true }, | - | ||||||||||||||||||
| 27 | { true , true , true , true , false, true , true , false, true , true , false, true , true }, | - | ||||||||||||||||||
| 28 | }; | - | ||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | } | - | ||||||||||||||||||
| 31 | - | |||||||||||||||||||
| 32 | static void getGraphemeBreaks(const ushort *string, quint32 len, QCharAttributes *attributes) | - | ||||||||||||||||||
| 33 | { | - | ||||||||||||||||||
| 34 | QUnicodeTables::GraphemeBreakClass lcls = QUnicodeTables::GraphemeBreak_LF; | - | ||||||||||||||||||
| 35 | for (quint32 i = 0; i != len; ++i) { | - | ||||||||||||||||||
| 36 | quint32 pos = i; | - | ||||||||||||||||||
| 37 | uint ucs4 = string[i]; | - | ||||||||||||||||||
| 38 | if (QChar::isHighSurrogate(ucs4) && i + 1 != len) { | - | ||||||||||||||||||
| 39 | ushort low = string[i + 1]; | - | ||||||||||||||||||
| 40 | if (QChar::isLowSurrogate(low)) { | - | ||||||||||||||||||
| 41 | ucs4 = QChar::surrogateToUcs4(ucs4, low); | - | ||||||||||||||||||
| 42 | ++i; | - | ||||||||||||||||||
| 43 | } | - | ||||||||||||||||||
| 44 | } | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ucs4); | - | ||||||||||||||||||
| 47 | QUnicodeTables::GraphemeBreakClass cls = (QUnicodeTables::GraphemeBreakClass) prop->graphemeBreakClass; | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | if (__builtin_expect(!!(GB::breakTable[lcls][cls]), true)) | - | ||||||||||||||||||
| 50 | attributes[pos].graphemeBoundary = true; | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | lcls = cls; | - | ||||||||||||||||||
| 53 | } | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | attributes[len].graphemeBoundary = true; | - | ||||||||||||||||||
| 56 | } | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | namespace WB { | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | enum Action { | - | ||||||||||||||||||
| 62 | NoBreak, | - | ||||||||||||||||||
| 63 | Break, | - | ||||||||||||||||||
| 64 | Lookup, | - | ||||||||||||||||||
| 65 | LookupW | - | ||||||||||||||||||
| 66 | }; | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | static const uchar breakTable[QUnicodeTables::WordBreak_ExtendNumLet + 1][QUnicodeTables::WordBreak_ExtendNumLet + 1] = { | - | ||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | { Break , Break , Break , Break , NoBreak, Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 71 | { Break , Break , NoBreak, Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 72 | { Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 73 | { Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 74 | { Break , Break , Break , Break , NoBreak, Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 75 | { Break , Break , Break , Break , NoBreak, NoBreak, Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 76 | { Break , Break , Break , Break , NoBreak, Break , NoBreak, Break , Break , Break , Break , Break , Break , Break , Break , NoBreak }, | - | ||||||||||||||||||
| 77 | { Break , Break , Break , Break , NoBreak, Break , Break , NoBreak, NoBreak, LookupW, Lookup , LookupW, LookupW, Break , NoBreak, NoBreak }, | - | ||||||||||||||||||
| 78 | { Break , Break , Break , Break , NoBreak, Break , Break , NoBreak, NoBreak, LookupW, Break , LookupW, LookupW, Break , NoBreak, NoBreak }, | - | ||||||||||||||||||
| 79 | { Break , Break , Break , Break , NoBreak, Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 80 | { Break , Break , Break , Break , NoBreak, Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 81 | { Break , Break , Break , Break , NoBreak, Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 82 | { Break , Break , Break , Break , NoBreak, Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 83 | { Break , Break , Break , Break , NoBreak, Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 84 | { Break , Break , Break , Break , NoBreak, Break , Break , NoBreak, NoBreak, Lookup , Break , Lookup , Break , Lookup , NoBreak, NoBreak }, | - | ||||||||||||||||||
| 85 | { Break , Break , Break , Break , NoBreak, Break , NoBreak, NoBreak, NoBreak, Break , Break , Break , Break , Break , NoBreak, NoBreak }, | - | ||||||||||||||||||
| 86 | }; | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | } | - | ||||||||||||||||||
| 89 | - | |||||||||||||||||||
| 90 | static void getWordBreaks(const ushort *string, quint32 len, QCharAttributes *attributes) | - | ||||||||||||||||||
| 91 | { | - | ||||||||||||||||||
| 92 | enum WordType { | - | ||||||||||||||||||
| 93 | WordTypeNone, WordTypeAlphaNumeric, WordTypeHiraganaKatakana | - | ||||||||||||||||||
| 94 | } currentWordType = WordTypeNone; | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | QUnicodeTables::WordBreakClass cls = QUnicodeTables::WordBreak_LF; | - | ||||||||||||||||||
| 97 | for (quint32 i = 0; i != len; ++i) { | - | ||||||||||||||||||
| 98 | quint32 pos = i; | - | ||||||||||||||||||
| 99 | uint ucs4 = string[i]; | - | ||||||||||||||||||
| 100 | if (QChar::isHighSurrogate(ucs4) && i + 1 != len) { | - | ||||||||||||||||||
| 101 | ushort low = string[i + 1]; | - | ||||||||||||||||||
| 102 | if (QChar::isLowSurrogate(low)) { | - | ||||||||||||||||||
| 103 | ucs4 = QChar::surrogateToUcs4(ucs4, low); | - | ||||||||||||||||||
| 104 | ++i; | - | ||||||||||||||||||
| 105 | } | - | ||||||||||||||||||
| 106 | } | - | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ucs4); | - | ||||||||||||||||||
| 109 | QUnicodeTables::WordBreakClass ncls = (QUnicodeTables::WordBreakClass) prop->wordBreakClass; | - | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | if (qt_initcharattributes_default_algorithm_only) { | - | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | if (ucs4 == 0x002E) | - | ||||||||||||||||||
| 117 | ncls = QUnicodeTables::WordBreak_MidNumLet; | - | ||||||||||||||||||
| 118 | else if (ucs4 == 0x003A) | - | ||||||||||||||||||
| 119 | ncls = QUnicodeTables::WordBreak_MidLetter; | - | ||||||||||||||||||
| 120 | } | - | ||||||||||||||||||
| 121 | - | |||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | uchar action = WB::breakTable[cls][ncls]; | - | ||||||||||||||||||
| 124 | switch (action) { | - | ||||||||||||||||||
| 125 | case WB::Break: | - | ||||||||||||||||||
| 126 | break; | - | ||||||||||||||||||
| 127 | case WB::NoBreak: | - | ||||||||||||||||||
| 128 | if (__builtin_expect(!!(ncls == QUnicodeTables::WordBreak_Extend), false)) { | - | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | continue; | - | ||||||||||||||||||
| 131 | } | - | ||||||||||||||||||
| 132 | break; | - | ||||||||||||||||||
| 133 | case WB::Lookup: | - | ||||||||||||||||||
| 134 | case WB::LookupW: | - | ||||||||||||||||||
| 135 | for (quint32 lookahead = i + 1; lookahead < len; ++lookahead) { | - | ||||||||||||||||||
| 136 | ucs4 = string[lookahead]; | - | ||||||||||||||||||
| 137 | if (QChar::isHighSurrogate(ucs4) && lookahead + 1 != len) { | - | ||||||||||||||||||
| 138 | ushort low = string[lookahead + 1]; | - | ||||||||||||||||||
| 139 | if (QChar::isLowSurrogate(low)) { | - | ||||||||||||||||||
| 140 | ucs4 = QChar::surrogateToUcs4(ucs4, low); | - | ||||||||||||||||||
| 141 | ++lookahead; | - | ||||||||||||||||||
| 142 | } | - | ||||||||||||||||||
| 143 | } | - | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | prop = QUnicodeTables::properties(ucs4); | - | ||||||||||||||||||
| 146 | QUnicodeTables::WordBreakClass tcls = (QUnicodeTables::WordBreakClass) prop->wordBreakClass; | - | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | if (__builtin_expect(!!(tcls == QUnicodeTables::WordBreak_Extend), false)) { | - | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | continue; | - | ||||||||||||||||||
| 151 | } | - | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | if (__builtin_expect(!!(tcls == cls || (action == WB::LookupW && (tcls == QUnicodeTables::WordBreak_HebrewLetter || tcls == QUnicodeTables::WordBreak_ALetter))), true) | - | ||||||||||||||||||
| 154 | ) { | - | ||||||||||||||||||
| 155 | i = lookahead; | - | ||||||||||||||||||
| 156 | ncls = tcls; | - | ||||||||||||||||||
| 157 | action = WB::NoBreak; | - | ||||||||||||||||||
| 158 | } | - | ||||||||||||||||||
| 159 | break; | - | ||||||||||||||||||
| 160 | } | - | ||||||||||||||||||
| 161 | if (action != WB::NoBreak) { | - | ||||||||||||||||||
| 162 | action = WB::Break; | - | ||||||||||||||||||
| 163 | if (__builtin_expect(!!(ncls == QUnicodeTables::WordBreak_SingleQuote && cls == QUnicodeTables::WordBreak_HebrewLetter), false)) | - | ||||||||||||||||||
| 164 | action = WB::NoBreak; | - | ||||||||||||||||||
| 165 | } | - | ||||||||||||||||||
| 166 | break; | - | ||||||||||||||||||
| 167 | } | - | ||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | cls = ncls; | - | ||||||||||||||||||
| 170 | if (action == WB::Break) { | - | ||||||||||||||||||
| 171 | attributes[pos].wordBreak = true; | - | ||||||||||||||||||
| 172 | if (currentWordType != WordTypeNone) | - | ||||||||||||||||||
| 173 | attributes[pos].wordEnd = true; | - | ||||||||||||||||||
| 174 | switch (cls) { | - | ||||||||||||||||||
| 175 | case QUnicodeTables::WordBreak_Katakana: | - | ||||||||||||||||||
| 176 | currentWordType = WordTypeHiraganaKatakana; | - | ||||||||||||||||||
| 177 | attributes[pos].wordStart = true; | - | ||||||||||||||||||
| 178 | break; | - | ||||||||||||||||||
| 179 | case QUnicodeTables::WordBreak_HebrewLetter: | - | ||||||||||||||||||
| 180 | case QUnicodeTables::WordBreak_ALetter: | - | ||||||||||||||||||
| 181 | case QUnicodeTables::WordBreak_Numeric: | - | ||||||||||||||||||
| 182 | currentWordType = WordTypeAlphaNumeric; | - | ||||||||||||||||||
| 183 | attributes[pos].wordStart = true; | - | ||||||||||||||||||
| 184 | break; | - | ||||||||||||||||||
| 185 | default: | - | ||||||||||||||||||
| 186 | currentWordType = WordTypeNone; | - | ||||||||||||||||||
| 187 | break; | - | ||||||||||||||||||
| 188 | } | - | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | } | - | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | if (currentWordType != WordTypeNone) | - | ||||||||||||||||||
| 193 | attributes[len].wordEnd = true; | - | ||||||||||||||||||
| 194 | attributes[len].wordBreak = true; | - | ||||||||||||||||||
| 195 | } | - | ||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | namespace SB { | - | ||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | enum State { | - | ||||||||||||||||||
| 201 | Initial, | - | ||||||||||||||||||
| 202 | Lower, | - | ||||||||||||||||||
| 203 | Upper, | - | ||||||||||||||||||
| 204 | LUATerm, | - | ||||||||||||||||||
| 205 | ATerm, | - | ||||||||||||||||||
| 206 | ATermC, | - | ||||||||||||||||||
| 207 | ACS, | - | ||||||||||||||||||
| 208 | STerm, | - | ||||||||||||||||||
| 209 | STermC, | - | ||||||||||||||||||
| 210 | SCS, | - | ||||||||||||||||||
| 211 | BAfterC, | - | ||||||||||||||||||
| 212 | BAfter, | - | ||||||||||||||||||
| 213 | Break, | - | ||||||||||||||||||
| 214 | Lookup | - | ||||||||||||||||||
| 215 | }; | - | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | static const uchar breakTable[BAfter + 1][QUnicodeTables::SentenceBreak_Close + 1] = { | - | ||||||||||||||||||
| 218 | - | |||||||||||||||||||
| 219 | { Initial, BAfterC, BAfter , BAfter , Initial, Initial, Lower , Upper , Initial, Initial, ATerm , Initial, STerm , Initial }, | - | ||||||||||||||||||
| 220 | { Initial, BAfterC, BAfter , BAfter , Lower , Initial, Initial, Initial, Initial, Initial, LUATerm, Initial, STerm , Initial }, | - | ||||||||||||||||||
| 221 | { Initial, BAfterC, BAfter , BAfter , Upper , Initial, Initial, Upper , Initial, Initial, LUATerm, STerm , STerm , Initial }, | - | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | { Lookup , BAfterC, BAfter , BAfter , LUATerm, ACS , Initial, Upper , Break , Initial, ATerm , STerm , STerm , ATermC }, | - | ||||||||||||||||||
| 224 | { Lookup , BAfterC, BAfter , BAfter , ATerm , ACS , Initial, Break , Break , Initial, ATerm , STerm , STerm , ATermC }, | - | ||||||||||||||||||
| 225 | { Lookup , BAfterC, BAfter , BAfter , ATermC , ACS , Initial, Break , Break , Lookup , ATerm , STerm , STerm , ATermC }, | - | ||||||||||||||||||
| 226 | { Lookup , BAfterC, BAfter , BAfter , ACS , ACS , Initial, Break , Break , Lookup , ATerm , STerm , STerm , Lookup }, | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | { Break , BAfterC, BAfter , BAfter , STerm , SCS , Break , Break , Break , Break , ATerm , STerm , STerm , STermC }, | - | ||||||||||||||||||
| 229 | { Break , BAfterC, BAfter , BAfter , STermC , SCS , Break , Break , Break , Break , ATerm , STerm , STerm , STermC }, | - | ||||||||||||||||||
| 230 | { Break , BAfterC, BAfter , BAfter , SCS , SCS , Break , Break , Break , Break , ATerm , STerm , STerm , Break }, | - | ||||||||||||||||||
| 231 | { Break , Break , BAfter , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 232 | { Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break , Break }, | - | ||||||||||||||||||
| 233 | }; | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | } | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | static void getSentenceBreaks(const ushort *string, quint32 len, QCharAttributes *attributes) | - | ||||||||||||||||||
| 238 | { | - | ||||||||||||||||||
| 239 | uchar state = SB::BAfter; | - | ||||||||||||||||||
| 240 | for (quint32 i = 0; i != len; ++i) { | - | ||||||||||||||||||
| 241 | quint32 pos = i; | - | ||||||||||||||||||
| 242 | uint ucs4 = string[i]; | - | ||||||||||||||||||
| 243 | if (QChar::isHighSurrogate(ucs4) && i + 1 != len) { | - | ||||||||||||||||||
| 244 | ushort low = string[i + 1]; | - | ||||||||||||||||||
| 245 | if (QChar::isLowSurrogate(low)) { | - | ||||||||||||||||||
| 246 | ucs4 = QChar::surrogateToUcs4(ucs4, low); | - | ||||||||||||||||||
| 247 | ++i; | - | ||||||||||||||||||
| 248 | } | - | ||||||||||||||||||
| 249 | } | - | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ucs4); | - | ||||||||||||||||||
| 252 | QUnicodeTables::SentenceBreakClass ncls = (QUnicodeTables::SentenceBreakClass) prop->sentenceBreakClass; | - | ||||||||||||||||||
| 253 | - | |||||||||||||||||||
| 254 | ((!(state <= SB::BAfter)) ? qt_assert("state <= SB::BAfter",__FILE__,299305) : qt_noop()); | - | ||||||||||||||||||
| 255 | state = SB::breakTable[state][ncls]; | - | ||||||||||||||||||
| 256 | if (__builtin_expect(!!(state == SB::Lookup), false)) { | - | ||||||||||||||||||
| 257 | state = SB::Break; | - | ||||||||||||||||||
| 258 | for (quint32 lookahead = i + 1; lookahead < len; ++lookahead) { | - | ||||||||||||||||||
| 259 | ucs4 = string[lookahead]; | - | ||||||||||||||||||
| 260 | if (QChar::isHighSurrogate(ucs4) && lookahead + 1 != len) { | - | ||||||||||||||||||
| 261 | ushort low = string[lookahead + 1]; | - | ||||||||||||||||||
| 262 | if (QChar::isLowSurrogate(low)) { | - | ||||||||||||||||||
| 263 | ucs4 = QChar::surrogateToUcs4(ucs4, low); | - | ||||||||||||||||||
| 264 | ++lookahead; | - | ||||||||||||||||||
| 265 | } | - | ||||||||||||||||||
| 266 | } | - | ||||||||||||||||||
| 267 | - | |||||||||||||||||||
| 268 | prop = QUnicodeTables::properties(ucs4); | - | ||||||||||||||||||
| 269 | QUnicodeTables::SentenceBreakClass tcls = (QUnicodeTables::SentenceBreakClass) prop->sentenceBreakClass; | - | ||||||||||||||||||
| 270 | switch (tcls) { | - | ||||||||||||||||||
| 271 | case QUnicodeTables::SentenceBreak_Other: | - | ||||||||||||||||||
| 272 | case QUnicodeTables::SentenceBreak_Extend: | - | ||||||||||||||||||
| 273 | case QUnicodeTables::SentenceBreak_Sp: | - | ||||||||||||||||||
| 274 | case QUnicodeTables::SentenceBreak_Numeric: | - | ||||||||||||||||||
| 275 | case QUnicodeTables::SentenceBreak_SContinue: | - | ||||||||||||||||||
| 276 | case QUnicodeTables::SentenceBreak_Close: | - | ||||||||||||||||||
| 277 | continue; | - | ||||||||||||||||||
| 278 | case QUnicodeTables::SentenceBreak_Lower: | - | ||||||||||||||||||
| 279 | i = lookahead; | - | ||||||||||||||||||
| 280 | state = SB::Initial; | - | ||||||||||||||||||
| 281 | break; | - | ||||||||||||||||||
| 282 | default: | - | ||||||||||||||||||
| 283 | break; | - | ||||||||||||||||||
| 284 | } | - | ||||||||||||||||||
| 285 | break; | - | ||||||||||||||||||
| 286 | } | - | ||||||||||||||||||
| 287 | } | - | ||||||||||||||||||
| 288 | if (__builtin_expect(!!(state == SB::Break), false)) { | - | ||||||||||||||||||
| 289 | attributes[pos].sentenceBoundary = true; | - | ||||||||||||||||||
| 290 | state = SB::breakTable[SB::Initial][ncls]; | - | ||||||||||||||||||
| 291 | } | - | ||||||||||||||||||
| 292 | } | - | ||||||||||||||||||
| 293 | - | |||||||||||||||||||
| 294 | attributes[len].sentenceBoundary = true; | - | ||||||||||||||||||
| 295 | } | - | ||||||||||||||||||
| 296 | namespace LB { | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | namespace NS { | - | ||||||||||||||||||
| 299 | - | |||||||||||||||||||
| 300 | - | |||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | - | |||||||||||||||||||
| 304 | enum Action { | - | ||||||||||||||||||
| 305 | None, | - | ||||||||||||||||||
| 306 | Start, | - | ||||||||||||||||||
| 307 | Continue, | - | ||||||||||||||||||
| 308 | Break | - | ||||||||||||||||||
| 309 | }; | - | ||||||||||||||||||
| 310 | - | |||||||||||||||||||
| 311 | enum Class { | - | ||||||||||||||||||
| 312 | XX, | - | ||||||||||||||||||
| 313 | PRPO, | - | ||||||||||||||||||
| 314 | OPHY, | - | ||||||||||||||||||
| 315 | NU, | - | ||||||||||||||||||
| 316 | SYIS, | - | ||||||||||||||||||
| 317 | CLCP | - | ||||||||||||||||||
| 318 | }; | - | ||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | static const uchar actionTable[CLCP + 1][CLCP + 1] = { | - | ||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | { None , Start , Start , Start , None , None }, | - | ||||||||||||||||||
| 323 | { None , Start , Continue, Continue, None , None }, | - | ||||||||||||||||||
| 324 | { None , Start , Start , Continue, None , None }, | - | ||||||||||||||||||
| 325 | { Break , Break , Break , Continue, Continue, Continue }, | - | ||||||||||||||||||
| 326 | { Break , Break , Break , Continue, Continue, Continue }, | - | ||||||||||||||||||
| 327 | { Break , Continue, Break , Break , Break , Break }, | - | ||||||||||||||||||
| 328 | }; | - | ||||||||||||||||||
| 329 | - | |||||||||||||||||||
| 330 | inline Class toClass(QUnicodeTables::LineBreakClass lbc, QChar::Category category) | - | ||||||||||||||||||
| 331 | { | - | ||||||||||||||||||
| 332 | switch (lbc) { | - | ||||||||||||||||||
| 333 | case QUnicodeTables::LineBreak_AL: | - | ||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | if (category == QChar::Symbol_Math) | - | ||||||||||||||||||
| 336 | return SYIS; | - | ||||||||||||||||||
| 337 | break; | - | ||||||||||||||||||
| 338 | case QUnicodeTables::LineBreak_PR: case QUnicodeTables::LineBreak_PO: | - | ||||||||||||||||||
| 339 | return PRPO; | - | ||||||||||||||||||
| 340 | case QUnicodeTables::LineBreak_OP: case QUnicodeTables::LineBreak_HY: | - | ||||||||||||||||||
| 341 | return OPHY; | - | ||||||||||||||||||
| 342 | case QUnicodeTables::LineBreak_NU: | - | ||||||||||||||||||
| 343 | return NU; | - | ||||||||||||||||||
| 344 | case QUnicodeTables::LineBreak_SY: case QUnicodeTables::LineBreak_IS: | - | ||||||||||||||||||
| 345 | return SYIS; | - | ||||||||||||||||||
| 346 | case QUnicodeTables::LineBreak_CL: case QUnicodeTables::LineBreak_CP: | - | ||||||||||||||||||
| 347 | return CLCP; | - | ||||||||||||||||||
| 348 | default: | - | ||||||||||||||||||
| 349 | break; | - | ||||||||||||||||||
| 350 | } | - | ||||||||||||||||||
| 351 | return XX; | - | ||||||||||||||||||
| 352 | } | - | ||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | } | - | ||||||||||||||||||
| 355 | enum Action { | - | ||||||||||||||||||
| 356 | ProhibitedBreak, PB = ProhibitedBreak, | - | ||||||||||||||||||
| 357 | DirectBreak, DB = DirectBreak, | - | ||||||||||||||||||
| 358 | IndirectBreak, IB = IndirectBreak, | - | ||||||||||||||||||
| 359 | CombiningIndirectBreak, CI = CombiningIndirectBreak, | - | ||||||||||||||||||
| 360 | CombiningProhibitedBreak, CP = CombiningProhibitedBreak, | - | ||||||||||||||||||
| 361 | ProhibitedBreakAfterHebrewPlusHyphen, HH = ProhibitedBreakAfterHebrewPlusHyphen | - | ||||||||||||||||||
| 362 | }; | - | ||||||||||||||||||
| 363 | - | |||||||||||||||||||
| 364 | static const uchar breakTable[QUnicodeTables::LineBreak_CB + 1][QUnicodeTables::LineBreak_CB + 1] = { | - | ||||||||||||||||||
| 365 | - | |||||||||||||||||||
| 366 | { PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, CP, PB, PB, PB, PB, PB, PB, PB, PB }, | - | ||||||||||||||||||
| 367 | { DB, PB, PB, IB, IB, PB, PB, PB, PB, DB, DB, DB, DB, DB, DB, DB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 368 | { DB, PB, PB, IB, IB, PB, PB, PB, PB, DB, DB, IB, IB, IB, DB, DB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 369 | { PB, PB, PB, IB, IB, IB, PB, PB, PB, IB, IB, IB, IB, IB, IB, IB, IB, IB, IB, IB, PB, CI, PB, IB, IB, IB, IB, IB, IB, IB }, | - | ||||||||||||||||||
| 370 | { IB, PB, PB, IB, IB, IB, PB, PB, PB, IB, IB, IB, IB, IB, IB, IB, IB, IB, IB, IB, PB, CI, PB, IB, IB, IB, IB, IB, IB, IB }, | - | ||||||||||||||||||
| 371 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, DB, DB, DB, DB, DB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 372 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, DB, DB, DB, DB, IB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 373 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, DB, DB, IB, DB, DB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 374 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, DB, IB, IB, DB, DB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 375 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, IB, IB, IB, IB, DB, IB, IB, DB, DB, PB, CI, PB, IB, IB, IB, IB, IB, DB, DB }, | - | ||||||||||||||||||
| 376 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, IB, IB, IB, DB, DB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 377 | { IB, PB, PB, IB, IB, IB, PB, PB, PB, IB, IB, IB, IB, IB, DB, IB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 378 | { IB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, IB, IB, IB, DB, IB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 379 | { IB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, IB, IB, IB, DB, IB, CI, CI, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 380 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, IB, DB, DB, DB, DB, IB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 381 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, DB, DB, DB, DB, IB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 382 | { HH, PB, PB, IB, HH, IB, PB, PB, PB, HH, HH, IB, HH, HH, HH, HH, IB, IB, HH, HH, PB, CI, PB, HH, HH, HH, HH, HH, HH, DB }, | - | ||||||||||||||||||
| 383 | { HH, PB, PB, IB, HH, IB, PB, PB, PB, HH, HH, HH, HH, HH, HH, HH, IB, IB, HH, HH, PB, CI, PB, HH, HH, HH, HH, HH, HH, DB }, | - | ||||||||||||||||||
| 384 | { IB, PB, PB, IB, IB, IB, PB, PB, PB, IB, IB, IB, IB, IB, IB, IB, IB, IB, IB, IB, PB, CI, PB, IB, IB, IB, IB, IB, IB, DB }, | - | ||||||||||||||||||
| 385 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, DB, DB, DB, DB, DB, IB, IB, DB, PB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 386 | { DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, PB, DB, DB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 387 | { IB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, IB, IB, IB, DB, IB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB }, | - | ||||||||||||||||||
| 388 | { IB, PB, PB, IB, IB, IB, PB, PB, PB, IB, IB, IB, IB, IB, IB, IB, IB, IB, IB, IB, PB, CI, PB, IB, IB, IB, IB, IB, IB, IB }, | - | ||||||||||||||||||
| 389 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, IB, DB, DB, DB, DB, IB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, IB, IB, DB, DB }, | - | ||||||||||||||||||
| 390 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, IB, DB, DB, DB, DB, IB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, IB, DB, DB }, | - | ||||||||||||||||||
| 391 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, IB, DB, DB, DB, DB, IB, IB, IB, DB, DB, PB, CI, PB, IB, IB, IB, IB, DB, DB, DB }, | - | ||||||||||||||||||
| 392 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, IB, DB, DB, DB, DB, IB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, IB, IB, DB, DB }, | - | ||||||||||||||||||
| 393 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, IB, DB, DB, DB, DB, IB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, IB, DB, DB }, | - | ||||||||||||||||||
| 394 | { DB, PB, PB, IB, IB, IB, PB, PB, PB, DB, DB, DB, DB, DB, DB, DB, IB, IB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, IB, DB }, | - | ||||||||||||||||||
| 395 | { DB, PB, PB, IB, IB, DB, PB, PB, PB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, DB, PB, CI, PB, DB, DB, DB, DB, DB, DB, DB } | - | ||||||||||||||||||
| 396 | }; | - | ||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | - | |||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | } | - | ||||||||||||||||||
| 403 | - | |||||||||||||||||||
| 404 | static void getLineBreaks(const ushort *string, quint32 len, QCharAttributes *attributes) | - | ||||||||||||||||||
| 405 | { | - | ||||||||||||||||||
| 406 | quint32 nestart = 0; | - | ||||||||||||||||||
| 407 | LB::NS::Class nelast = LB::NS::XX; | - | ||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | QUnicodeTables::LineBreakClass lcls = QUnicodeTables::LineBreak_LF; | - | ||||||||||||||||||
| 410 | QUnicodeTables::LineBreakClass cls = lcls; | - | ||||||||||||||||||
| 411 | for (quint32 i = 0; i != len; ++i) { | - | ||||||||||||||||||
| 412 | quint32 pos = i; | - | ||||||||||||||||||
| 413 | uint ucs4 = string[i]; | - | ||||||||||||||||||
| 414 | if (QChar::isHighSurrogate(ucs4) && i + 1 != len) { | - | ||||||||||||||||||
| 415 | ushort low = string[i + 1]; | - | ||||||||||||||||||
| 416 | if (QChar::isLowSurrogate(low)) { | - | ||||||||||||||||||
| 417 | ucs4 = QChar::surrogateToUcs4(ucs4, low); | - | ||||||||||||||||||
| 418 | ++i; | - | ||||||||||||||||||
| 419 | } | - | ||||||||||||||||||
| 420 | } | - | ||||||||||||||||||
| 421 | - | |||||||||||||||||||
| 422 | const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ucs4); | - | ||||||||||||||||||
| 423 | QUnicodeTables::LineBreakClass ncls = (QUnicodeTables::LineBreakClass) prop->lineBreakClass; | - | ||||||||||||||||||
| 424 | - | |||||||||||||||||||
| 425 | if (__builtin_expect(!!(ncls == QUnicodeTables::LineBreak_SA), false)) { | - | ||||||||||||||||||
| 426 | - | |||||||||||||||||||
| 427 | static const int test = (1 << (QChar::Mark_NonSpacing)) | (1 << (QChar::Mark_SpacingCombining)); | - | ||||||||||||||||||
| 428 | if ((1 << (prop->category)) & test) | - | ||||||||||||||||||
| 429 | ncls = QUnicodeTables::LineBreak_CM; | - | ||||||||||||||||||
| 430 | } | - | ||||||||||||||||||
| 431 | if (__builtin_expect(!!(ncls == QUnicodeTables::LineBreak_CM), false)) { | - | ||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | if (lcls == QUnicodeTables::LineBreak_ZW || lcls >= QUnicodeTables::LineBreak_SP) | - | ||||||||||||||||||
| 434 | ncls = QUnicodeTables::LineBreak_AL; | - | ||||||||||||||||||
| 435 | } | - | ||||||||||||||||||
| 436 | - | |||||||||||||||||||
| 437 | if (__builtin_expect(!!(ncls != QUnicodeTables::LineBreak_CM), true)) { | - | ||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | LB::NS::Class necur = LB::NS::toClass(ncls, (QChar::Category)prop->category); | - | ||||||||||||||||||
| 440 | switch (LB::NS::actionTable[nelast][necur]) { | - | ||||||||||||||||||
| 441 | case LB::NS::Break: | - | ||||||||||||||||||
| 442 | - | |||||||||||||||||||
| 443 | for (quint32 j = nestart + 1; j < pos; ++j) | - | ||||||||||||||||||
| 444 | attributes[j].lineBreak = false; | - | ||||||||||||||||||
| 445 | - | |||||||||||||||||||
| 446 | case LB::NS::None: | - | ||||||||||||||||||
| 447 | nelast = LB::NS::XX; | - | ||||||||||||||||||
| 448 | break; | - | ||||||||||||||||||
| 449 | case LB::NS::Start: | - | ||||||||||||||||||
| 450 | nestart = i; | - | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | default: | - | ||||||||||||||||||
| 453 | nelast = necur; | - | ||||||||||||||||||
| 454 | break; | - | ||||||||||||||||||
| 455 | } | - | ||||||||||||||||||
| 456 | } | - | ||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | if (__builtin_expect(!!(lcls >= QUnicodeTables::LineBreak_CR), false)) { | - | ||||||||||||||||||
| 459 | - | |||||||||||||||||||
| 460 | if (lcls > QUnicodeTables::LineBreak_CR || ncls != QUnicodeTables::LineBreak_LF) | - | ||||||||||||||||||
| 461 | attributes[pos].lineBreak = attributes[pos].mandatoryBreak = true; | - | ||||||||||||||||||
| 462 | goto next; | - | ||||||||||||||||||
| 463 | } | - | ||||||||||||||||||
| 464 | - | |||||||||||||||||||
| 465 | if (__builtin_expect(!!(ncls >= QUnicodeTables::LineBreak_SP), false)) { | - | ||||||||||||||||||
| 466 | if (ncls > QUnicodeTables::LineBreak_SP) | - | ||||||||||||||||||
| 467 | goto next; | - | ||||||||||||||||||
| 468 | goto next_no_cls_update; | - | ||||||||||||||||||
| 469 | } | - | ||||||||||||||||||
| 470 | - | |||||||||||||||||||
| 471 | - | |||||||||||||||||||
| 472 | - | |||||||||||||||||||
| 473 | if (__builtin_expect(!!(cls >= QUnicodeTables::LineBreak_SA), false)) | - | ||||||||||||||||||
| 474 | cls = QUnicodeTables::LineBreak_AL; | - | ||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | switch (LB::breakTable[cls][ncls < QUnicodeTables::LineBreak_SA ? ncls : QUnicodeTables::LineBreak_AL]) { | - | ||||||||||||||||||
| 477 | case LB::DirectBreak: | - | ||||||||||||||||||
| 478 | attributes[pos].lineBreak = true; | - | ||||||||||||||||||
| 479 | break; | - | ||||||||||||||||||
| 480 | case LB::IndirectBreak: | - | ||||||||||||||||||
| 481 | if (lcls == QUnicodeTables::LineBreak_SP) | - | ||||||||||||||||||
| 482 | attributes[pos].lineBreak = true; | - | ||||||||||||||||||
| 483 | break; | - | ||||||||||||||||||
| 484 | case LB::CombiningIndirectBreak: | - | ||||||||||||||||||
| 485 | if (lcls != QUnicodeTables::LineBreak_SP) | - | ||||||||||||||||||
| 486 | goto next_no_cls_update; | - | ||||||||||||||||||
| 487 | attributes[pos].lineBreak = true; | - | ||||||||||||||||||
| 488 | break; | - | ||||||||||||||||||
| 489 | case LB::CombiningProhibitedBreak: | - | ||||||||||||||||||
| 490 | if (lcls != QUnicodeTables::LineBreak_SP) | - | ||||||||||||||||||
| 491 | goto next_no_cls_update; | - | ||||||||||||||||||
| 492 | break; | - | ||||||||||||||||||
| 493 | case LB::ProhibitedBreakAfterHebrewPlusHyphen: | - | ||||||||||||||||||
| 494 | if (lcls != QUnicodeTables::LineBreak_HL) | - | ||||||||||||||||||
| 495 | attributes[pos].lineBreak = true; | - | ||||||||||||||||||
| 496 | break; | - | ||||||||||||||||||
| 497 | case LB::ProhibitedBreak: | - | ||||||||||||||||||
| 498 | - | |||||||||||||||||||
| 499 | default: | - | ||||||||||||||||||
| 500 | break; | - | ||||||||||||||||||
| 501 | } | - | ||||||||||||||||||
| 502 | - | |||||||||||||||||||
| 503 | next: | - | ||||||||||||||||||
| 504 | cls = ncls; | - | ||||||||||||||||||
| 505 | next_no_cls_update: | - | ||||||||||||||||||
| 506 | lcls = ncls; | - | ||||||||||||||||||
| 507 | } | - | ||||||||||||||||||
| 508 | - | |||||||||||||||||||
| 509 | if (__builtin_expect(!!(LB::NS::actionTable[nelast][LB::NS::XX] == LB::NS::Break), false)) { | - | ||||||||||||||||||
| 510 | - | |||||||||||||||||||
| 511 | for (quint32 j = nestart + 1; j < len; ++j) | - | ||||||||||||||||||
| 512 | attributes[j].lineBreak = false; | - | ||||||||||||||||||
| 513 | } | - | ||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | attributes[0].lineBreak = attributes[0].mandatoryBreak = false; | - | ||||||||||||||||||
| 516 | attributes[len].lineBreak = attributes[len].mandatoryBreak = true; | - | ||||||||||||||||||
| 517 | } | - | ||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | - | |||||||||||||||||||
| 520 | static void getWhiteSpaces(const ushort *string, quint32 len, QCharAttributes *attributes) | - | ||||||||||||||||||
| 521 | { | - | ||||||||||||||||||
| 522 | for (quint32 i = 0; i != len; ++i) { | - | ||||||||||||||||||
| 523 | uint ucs4 = string[i]; | - | ||||||||||||||||||
| 524 | if (QChar::isHighSurrogate(ucs4) && i + 1 != len) { | - | ||||||||||||||||||
| 525 | ushort low = string[i + 1]; | - | ||||||||||||||||||
| 526 | if (QChar::isLowSurrogate(low)) { | - | ||||||||||||||||||
| 527 | ucs4 = QChar::surrogateToUcs4(ucs4, low); | - | ||||||||||||||||||
| 528 | ++i; | - | ||||||||||||||||||
| 529 | } | - | ||||||||||||||||||
| 530 | } | - | ||||||||||||||||||
| 531 | - | |||||||||||||||||||
| 532 | if (__builtin_expect(!!(QChar::isSpace(ucs4)), false)) | - | ||||||||||||||||||
| 533 | attributes[i].whiteSpace = true; | - | ||||||||||||||||||
| 534 | } | - | ||||||||||||||||||
| 535 | } | - | ||||||||||||||||||
| 536 | - | |||||||||||||||||||
| 537 | - | |||||||||||||||||||
| 538 | __attribute__((visibility("default"))) void initCharAttributes(const ushort *string, int length, | - | ||||||||||||||||||
| 539 | const ScriptItem *items, int numItems, | - | ||||||||||||||||||
| 540 | QCharAttributes *attributes, CharAttributeOptions options) | - | ||||||||||||||||||
| 541 | { | - | ||||||||||||||||||
| 542 | if (length <= 0) | - | ||||||||||||||||||
| 543 | return; | - | ||||||||||||||||||
| 544 | - | |||||||||||||||||||
| 545 | if (!(options & DontClearAttributes)) | - | ||||||||||||||||||
| 546 | ::memset(attributes, 0, (length + 1) * sizeof(QCharAttributes)); | - | ||||||||||||||||||
| 547 | - | |||||||||||||||||||
| 548 | if (options & GraphemeBreaks) | - | ||||||||||||||||||
| 549 | getGraphemeBreaks(string, length, attributes); | - | ||||||||||||||||||
| 550 | if (options & WordBreaks) | - | ||||||||||||||||||
| 551 | getWordBreaks(string, length, attributes); | - | ||||||||||||||||||
| 552 | if (options & SentenceBreaks) | - | ||||||||||||||||||
| 553 | getSentenceBreaks(string, length, attributes); | - | ||||||||||||||||||
| 554 | if (options & LineBreaks) | - | ||||||||||||||||||
| 555 | getLineBreaks(string, length, attributes); | - | ||||||||||||||||||
| 556 | if (options & WhiteSpaces) | - | ||||||||||||||||||
| 557 | getWhiteSpaces(string, length, attributes); | - | ||||||||||||||||||
| 558 | - | |||||||||||||||||||
| 559 | if (!qt_initcharattributes_default_algorithm_only) { | - | ||||||||||||||||||
| 560 | if (!items || numItems <= 0) | - | ||||||||||||||||||
| 561 | return; | - | ||||||||||||||||||
| 562 | - | |||||||||||||||||||
| 563 | QVarLengthArray<HB_ScriptItem, 64> scriptItems; | - | ||||||||||||||||||
| 564 | scriptItems.reserve(numItems); | - | ||||||||||||||||||
| 565 | int start = 0; | - | ||||||||||||||||||
| 566 | HB_Script startScript = script_to_hbscript(items[start].script); | - | ||||||||||||||||||
| 567 | if (__builtin_expect(!!(startScript == HB_Script_Inherited), false)) | - | ||||||||||||||||||
| 568 | startScript = HB_Script_Common; | - | ||||||||||||||||||
| 569 | for (int i = start + 1; i < numItems; ++i) { | - | ||||||||||||||||||
| 570 | HB_Script script = script_to_hbscript(items[i].script); | - | ||||||||||||||||||
| 571 | if (__builtin_expect(!!(script == startScript || script == HB_Script_Inherited), true)) | - | ||||||||||||||||||
| 572 | continue; | - | ||||||||||||||||||
| 573 | ((!(items[i].position > items[start].position)) ? qt_assert("items[i].position > items[start].position",__FILE__,647653) : qt_noop()); | - | ||||||||||||||||||
| 574 | HB_ScriptItem item; | - | ||||||||||||||||||
| 575 | item.pos = items[start].position; | - | ||||||||||||||||||
| 576 | item.length = items[i].position - items[start].position; | - | ||||||||||||||||||
| 577 | item.script = startScript; | - | ||||||||||||||||||
| 578 | item.bidiLevel = 0; | - | ||||||||||||||||||
| 579 | scriptItems.append(item); | - | ||||||||||||||||||
| 580 | start = i; | - | ||||||||||||||||||
| 581 | startScript = script; | - | ||||||||||||||||||
| 582 | } | - | ||||||||||||||||||
| 583 | if (items[start].position + 1 < length) { | - | ||||||||||||||||||
| 584 | HB_ScriptItem item; | - | ||||||||||||||||||
| 585 | item.pos = items[start].position; | - | ||||||||||||||||||
| 586 | item.length = length - items[start].position; | - | ||||||||||||||||||
| 587 | item.script = startScript; | - | ||||||||||||||||||
| 588 | item.bidiLevel = 0; | - | ||||||||||||||||||
| 589 | scriptItems.append(item); | - | ||||||||||||||||||
| 590 | } | - | ||||||||||||||||||
| 591 | static_assert(bool(sizeof(QCharAttributes) == sizeof(HB_CharAttributes)), "sizeof(QCharAttributes) == sizeof(HB_CharAttributes)"); | - | ||||||||||||||||||
| 592 | HB_GetTailoredCharAttributes(string, length, | - | ||||||||||||||||||
| 593 | scriptItems.constData(), scriptItems.size(), | - | ||||||||||||||||||
| 594 | reinterpret_cast<HB_CharAttributes *>(attributes)); | - | ||||||||||||||||||
| 595 | } | - | ||||||||||||||||||
| 596 | } | - | ||||||||||||||||||
| 597 | __attribute__((visibility("default"))) void initScripts(const ushort *string, int length, uchar *scripts) | - | ||||||||||||||||||
| 598 | { | - | ||||||||||||||||||
| 599 | int sor = 0; | - | ||||||||||||||||||
| 600 | int eor = -10; | - | ||||||||||||||||||
| 601 | uchar script = QChar::Script_Common; | - | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | for (int i = 0; i < length
| 257027-6067506 | ||||||||||||||||||
| 604 | uint ucs4 = string[i]; | - | ||||||||||||||||||
| 605 | if (QChar::isHighSurrogate(ucs4)
| 28-6066585 | ||||||||||||||||||
| 606 | ushort low = string[i + 1]; | - | ||||||||||||||||||
| 607 | if (QChar::isLowSurrogate(low)
| 28-865 | ||||||||||||||||||
| 608 | ucs4 = QChar::surrogateToUcs4(ucs4, low); | - | ||||||||||||||||||
| 609 | ++i; | - | ||||||||||||||||||
| 610 | } executed 865 times by 2 tests: end of blockExecuted by:
| 865 | ||||||||||||||||||
| 611 | } executed 893 times by 2 tests: end of blockExecuted by:
| 893 | ||||||||||||||||||
| 612 | - | |||||||||||||||||||
| 613 | const QUnicodeTables::Properties *prop = QUnicodeTables::properties(ucs4); | - | ||||||||||||||||||
| 614 | - | |||||||||||||||||||
| 615 | uchar nscript = prop->script; | - | ||||||||||||||||||
| 616 | - | |||||||||||||||||||
| 617 | if (__builtin_expect(!!(prop->scriptnscript == script || prop->scriptnscript <= QChar::Script_InheritedScript_Common), true)
| 101464-5966042 | ||||||||||||||||||
| 618 | continue; executed 5966042 times by 116 tests: continue;Executed by:
| 5966042 | ||||||||||||||||||
| 619 | - | |||||||||||||||||||
| 620 | - | |||||||||||||||||||
| 621 | if (__builtin_expect(!!(script <= QChar::Script_Common), false
| 727-100737 | ||||||||||||||||||
| 622 | - | |||||||||||||||||||
| 623 | - | |||||||||||||||||||
| 624 | script = nscript; | - | ||||||||||||||||||
| 625 | continue; executed 100737 times by 112 tests: continue;Executed by:
| 100737 | ||||||||||||||||||
| 626 | } | - | ||||||||||||||||||
| 627 | - | |||||||||||||||||||
| 628 | - | |||||||||||||||||||
| 629 | - | |||||||||||||||||||
| 630 | - | |||||||||||||||||||
| 631 | static const int test = ((1 << (QChar::Mark_NonSpacing)) | (1 << (QChar::Mark_SpacingCombining)) | (1 << (QChar::Mark_Enclosing))); | - | ||||||||||||||||||
| 632 | if (__builtin_expect(!!((1 << (prop->category)) & test), false)
| 10-717 | ||||||||||||||||||
| 633 | { | 10 | ||||||||||||||||||
| if (__builtin_expect(!!(continue; executed 10 times by 1 test: continue;Executed by:
| ||||||||||||||||||||
| 634 | - | |||||||||||||||||||
| 635 | ((!(script > QChar::Script_Common|| prop->script <=)) ? qt_assert("script > QChar::Script_Common), trueScript_Common",__FILE__,723) : qt_noop()); | - | ||||||||||||||||||
| 636 | ((!(sor < eor)) continue; | - | ||||||||||||||||||
| script = QChar? qt_assert("sor < eor",__FILE__,724) : qt_noop()); | ||||||||||||||||||||
| 637 | ::Scriptmemset(prop->scripts + sor, script); | - | ||||||||||||||||||
| } | ||||||||||||||||||||
| while, (sor <eor - sor) scripts[* sizeof(uchar)); | ||||||||||||||||||||
| 638 | sor ++]= scripteor; | - | ||||||||||||||||||
| 639 | - | |||||||||||||||||||
| 640 | script = prop->scriptnscript; | - | ||||||||||||||||||
| 641 | } executed 717 times by 7 tests: end of blockExecuted by:
| 717 | ||||||||||||||||||
| 642 | - | |||||||||||||||||||
| 643 | ((!(script >= QChar::Script_Common)) ? qt_assert("script >= QChar::Script_Common",__FILE__,731) : qt_noop()); | - | ||||||||||||||||||
| 644 | ((!(eor === length; | - | ||||||||||||||||||
| while)) ? qt_assert(sor < eor"eor == length",__FILE__,732) : qt_noop()); | ||||||||||||||||||||
| 645 | ::memset(scripts [+ sor++] =, script;, (eor - sor) * sizeof(uchar)); | - | ||||||||||||||||||
| 646 | } executed 257027 times by 116 tests: end of blockExecuted by:
| 257027 | ||||||||||||||||||
| 647 | - | |||||||||||||||||||
| 648 | } | - | ||||||||||||||||||
| 649 | - | |||||||||||||||||||
| 650 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |