Changeset View
Changeset View
Standalone View
Standalone View
src/lib/text/kstringhandler.cpp
Show All 20 Lines | |||||
21 | 21 | | |||
22 | #include "kstringhandler.h" | 22 | #include "kstringhandler.h" | ||
23 | 23 | | |||
24 | #include <stdlib.h> // random() | 24 | #include <stdlib.h> // random() | ||
25 | 25 | | |||
26 | #include <QtCore/QRegExp> // for the word ranges | 26 | #include <QtCore/QRegExp> // for the word ranges | ||
27 | #include <QtCore/QCharRef> | 27 | #include <QtCore/QCharRef> | ||
28 | #include <QtCore/QMutableStringListIterator> | 28 | #include <QtCore/QMutableStringListIterator> | ||
29 | #include <QtCore/QVector> | ||||
29 | 30 | | |||
30 | // | 31 | // | ||
31 | // Capitalization routines | 32 | // Capitalization routines | ||
32 | // | 33 | // | ||
33 | QString KStringHandler::capwords(const QString &text) | 34 | QString KStringHandler::capwords(const QString &text) | ||
34 | { | 35 | { | ||
35 | if (text.isEmpty()) { | 36 | if (text.isEmpty()) { | ||
36 | return text; | 37 | return text; | ||
▲ Show 20 Lines • Show All 297 Lines • ▼ Show 20 Line(s) | 314 | for (int i = 0; i < text.length(); i++) { | |||
334 | if (breakAfter && !openingParens && !nextIsSpace && !singleQuote) { | 335 | if (breakAfter && !openingParens && !nextIsSpace && !singleQuote) { | ||
335 | result += zwsp; | 336 | result += zwsp; | ||
336 | } | 337 | } | ||
337 | } | 338 | } | ||
338 | 339 | | |||
339 | return result; | 340 | return result; | ||
340 | } | 341 | } | ||
341 | 342 | | |||
343 | int KStringHandler::logicalLength(const QString& text) | ||||
344 | { | ||||
345 | int length = 0; | ||||
346 | auto chrs = text.toUcs4(); | ||||
347 | for (auto chr : chrs) { | ||||
348 | auto script = QChar::script(chr); | ||||
349 | if (script == QChar::Script_Han || | ||||
350 | script == QChar::Script_Hangul || | ||||
351 | script == QChar::Script_Hiragana || | ||||
352 | script == QChar::Script_Katakana || | ||||
353 | script == QChar::Script_Yi || | ||||
354 | QChar::isHighSurrogate(chr)) { | ||||
355 | length += 2; | ||||
356 | } else { | ||||
357 | length += 1; | ||||
358 | } | ||||
359 | } | ||||
360 | return length; | ||||
361 | } |