12static void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
14 QUnicodeTools::ScriptItemArray scriptItems;
15 QUnicodeTools::initScripts(str, &scriptItems);
17 QUnicodeTools::CharAttributeOptions options;
19 case QTextBoundaryFinder::Grapheme: options |= QUnicodeTools::GraphemeBreaks;
break;
20 case QTextBoundaryFinder::Word: options |= QUnicodeTools::WordBreaks;
break;
21 case QTextBoundaryFinder::Sentence: options |= QUnicodeTools::SentenceBreaks;
break;
22 case QTextBoundaryFinder::Line: options |= QUnicodeTools::LineBreaks;
break;
25 QUnicodeTools::initCharAttributes(str, scriptItems.data(), scriptItems.size(), attributes, options);
112QTextBoundaryFinder::QTextBoundaryFinder(
const QTextBoundaryFinder &other)
113 : s(other.s), sv(other.sv), pos(other.pos)
116 if (other.attributes) {
117 Q_ASSERT(sv.size() > 0);
118 attributes = (QCharAttributes *) malloc((sv.size() + 1) *
sizeof(QCharAttributes));
119 Q_CHECK_PTR(attributes);
120 memcpy(attributes, other.attributes, (sv.size() + 1) *
sizeof(QCharAttributes));
138QTextBoundaryFinder &QTextBoundaryFinder::operator=(
const QTextBoundaryFinder &other)
143 if (other.attributes) {
144 Q_ASSERT(other.sv.size() > 0);
145 size_t newCapacity = (size_t(other.sv.size()) + 1) *
sizeof(QCharAttributes);
146 QCharAttributes *newD = (QCharAttributes *) realloc(freeBuffer ? attributes :
nullptr, newCapacity);
157 if (other.attributes) {
158 memcpy(attributes, other.attributes, (sv.size() + 1) *
sizeof(QCharAttributes));
162 attributes =
nullptr;
229QTextBoundaryFinder::QTextBoundaryFinder(BoundaryType type, QStringView string,
unsigned char *buffer, qsizetype bufferSize)
234 if (buffer && bufferSize /
int(
sizeof(QCharAttributes)) >= sv.size() + 1) {
235 attributes =
reinterpret_cast<QCharAttributes *>(buffer);
238 attributes = (QCharAttributes *) malloc((sv.size() + 1) *
sizeof(QCharAttributes));
239 Q_CHECK_PTR(attributes);
241 init(t, sv, attributes);
319qsizetype QTextBoundaryFinder::toNextBoundary()
321 if (!attributes || pos < 0 || pos >= sv.size()) {
329 while (pos < sv.size() && !attributes[pos].graphemeBoundary)
333 while (pos < sv.size() && !attributes[pos].wordBreak)
337 while (pos < sv.size() && !attributes[pos].sentenceBoundary)
341 while (pos < sv.size() && !attributes[pos].lineBreak)
354qsizetype QTextBoundaryFinder::toPreviousBoundary()
356 if (!attributes || pos <= 0 || pos > sv.size()) {
364 while (pos > 0 && !attributes[pos].graphemeBoundary)
368 while (pos > 0 && !attributes[pos].wordBreak)
372 while (pos > 0 && !attributes[pos].sentenceBoundary)
376 while (pos > 0 && !attributes[pos].lineBreak)
387bool QTextBoundaryFinder::isAtBoundary()
const
389 if (!attributes || pos < 0 || pos > sv.size())
394 return attributes[pos].graphemeBoundary;
396 return attributes[pos].wordBreak;
398 return attributes[pos].sentenceBoundary;
401 return attributes[pos].lineBreak || pos == 0;
409QTextBoundaryFinder::BoundaryReasons QTextBoundaryFinder::boundaryReasons()
const
411 BoundaryReasons reasons = NotAtBoundary;
412 if (!attributes || pos < 0 || pos > sv.size())
415 const QCharAttributes attr = attributes[pos];
418 if (attr.graphemeBoundary) {
419 reasons |= BreakOpportunity | StartOfItem | EndOfItem;
421 reasons &= (~EndOfItem);
422 else if (pos == sv.size())
423 reasons &= (~StartOfItem);
427 if (attr.wordBreak) {
428 reasons |= BreakOpportunity;
430 reasons |= StartOfItem;
432 reasons |= EndOfItem;
436 if (attr.sentenceBoundary) {
437 reasons |= BreakOpportunity | StartOfItem | EndOfItem;
439 reasons &= (~EndOfItem);
440 else if (pos == sv.size())
441 reasons &= (~StartOfItem);
446 if (attr.lineBreak || pos == 0) {
447 reasons |= BreakOpportunity;
448 if (attr.mandatoryBreak || pos == 0) {
449 reasons |= MandatoryBreak | StartOfItem | EndOfItem;
451 reasons &= (~EndOfItem);
452 else if (pos == sv.size())
453 reasons &= (~StartOfItem);
454 }
else if (pos > 0 && sv[pos - 1].unicode() == QChar::SoftHyphen) {
455 reasons |= SoftHyphen;
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)