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

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