1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:trivial-impl-only
4
5#ifndef QTEXTBOUNDARYFINDER_H
6#define QTEXTBOUNDARYFINDER_H
7
8#include <QtCore/qchar.h>
9#include <QtCore/qstring.h>
10
11QT_BEGIN_NAMESPACE
12
13
14struct QCharAttributes;
15
16class Q_CORE_EXPORT QTextBoundaryFinder
17{
18public:
19 QTextBoundaryFinder();
20 QTextBoundaryFinder(const QTextBoundaryFinder &other);
21 QTextBoundaryFinder &operator=(const QTextBoundaryFinder &other);
22 ~QTextBoundaryFinder();
23
24 enum BoundaryType {
25 Grapheme,
26 Word,
27 Sentence,
28 Line
29 };
30
31 enum BoundaryReason {
32 NotAtBoundary = 0,
33 BreakOpportunity = 0x1f,
34 StartOfItem = 0x20,
35 EndOfItem = 0x40,
36 MandatoryBreak = 0x80,
37 SoftHyphen = 0x100
38 };
39 Q_DECLARE_FLAGS( BoundaryReasons, BoundaryReason )
40
41 QTextBoundaryFinder(BoundaryType type, const QString &string);
42 QTextBoundaryFinder(BoundaryType type, const QChar *chars, qsizetype length, unsigned char *buffer = nullptr, qsizetype bufferSize = 0)
43 : QTextBoundaryFinder(type, QStringView(chars, length), buffer, bufferSize)
44 {}
45 QTextBoundaryFinder(BoundaryType type, QStringView str, unsigned char *buffer = nullptr, qsizetype bufferSize = 0);
46
47 inline bool isValid() const { return attributes; }
48
49 inline BoundaryType type() const { return t; }
50 QString string() const;
51
52 void toStart();
53 void toEnd();
54 qsizetype position() const;
55 void setPosition(qsizetype position);
56
57 qsizetype toNextBoundary();
58 qsizetype toPreviousBoundary();
59
60 bool isAtBoundary() const;
61 BoundaryReasons boundaryReasons() const;
62
63private:
64 BoundaryType t = Grapheme;
65 QString s;
66 QStringView sv;
67 qsizetype pos = 0;
68 uint freeBuffer : 1;
69 uint unused : 31;
70 QCharAttributes *attributes = nullptr;
71};
72
73Q_DECLARE_OPERATORS_FOR_FLAGS(QTextBoundaryFinder::BoundaryReasons)
74
75QT_END_NAMESPACE
76
77#endif
78
79

source code of qtbase/src/corelib/text/qtextboundaryfinder.h