File indexing completed on 2026-09-17 09:25:16
0001
0002
0003
0004
0005 #ifndef QTEXTBOUNDARYFINDER_H
0006 #define QTEXTBOUNDARYFINDER_H
0007
0008 #include <QtCore/qchar.h>
0009 #include <QtCore/qstring.h>
0010
0011 #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
0012 # include <array>
0013 #endif
0014
0015 QT_BEGIN_NAMESPACE
0016
0017 struct QCharAttributes;
0018
0019 class Q_CORE_EXPORT QTextBoundaryFinder
0020 {
0021 public:
0022 QTextBoundaryFinder();
0023 QTextBoundaryFinder(const QTextBoundaryFinder &other);
0024 QTextBoundaryFinder(QTextBoundaryFinder &&other) noexcept
0025 : s{std::move(other.s)},
0026 sv{other.sv},
0027 pos{other.pos},
0028 attributes{std::exchange(other.attributes, nullptr)}
0029 {
0030 t = other.t;
0031 freeBuffer = other.freeBuffer;
0032 QT7_ONLY(reserved = other.reserved;)
0033 }
0034 QTextBoundaryFinder &operator=(const QTextBoundaryFinder &other);
0035 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QTextBoundaryFinder)
0036 ~QTextBoundaryFinder();
0037
0038 void swap(QTextBoundaryFinder &other) noexcept
0039 {
0040 std::swap(t, other.t);
0041 s.swap(other.s);
0042 std::swap(sv, other.sv);
0043 std::swap(pos, other.pos);
0044 std::swap(freeBuffer, other.freeBuffer);
0045 qt_ptr_swap(attributes, other.attributes);
0046 QT7_ONLY(reserved.swap(other.reserved);)
0047 }
0048
0049 enum BoundaryType QT7_ONLY(: quint8) {
0050 Grapheme,
0051 Word,
0052 Sentence,
0053 Line
0054 };
0055
0056 enum BoundaryReason {
0057 NotAtBoundary = 0,
0058 BreakOpportunity = 0x1f,
0059 StartOfItem = 0x20,
0060 EndOfItem = 0x40,
0061 MandatoryBreak = 0x80,
0062 SoftHyphen = 0x100
0063 };
0064 Q_DECLARE_FLAGS( BoundaryReasons, BoundaryReason )
0065
0066 QTextBoundaryFinder(BoundaryType type, const QString &string);
0067 QTextBoundaryFinder(BoundaryType type, const QChar *chars, qsizetype length, unsigned char *buffer = nullptr, qsizetype bufferSize = 0)
0068 : QTextBoundaryFinder(type, QStringView(chars, length), buffer, bufferSize)
0069 {}
0070 QTextBoundaryFinder(BoundaryType type, QStringView str, unsigned char *buffer = nullptr, qsizetype bufferSize = 0);
0071
0072 inline bool isValid() const { return attributes; }
0073
0074 inline BoundaryType type() const { return t; }
0075 QString string() const;
0076
0077 void toStart();
0078 void toEnd();
0079 qsizetype position() const;
0080 void setPosition(qsizetype position);
0081
0082 qsizetype toNextBoundary();
0083 qsizetype toPreviousBoundary();
0084
0085 bool isAtBoundary() const;
0086 BoundaryReasons boundaryReasons() const;
0087
0088 private:
0089 QT6_ONLY(BoundaryType t = Grapheme;)
0090 QString s;
0091 QStringView sv;
0092 qsizetype pos = 0;
0093 QT6_ONLY(uint freeBuffer = true;)
0094 QCharAttributes *attributes = nullptr;
0095 #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
0096 bool freeBuffer = true;
0097 BoundaryType t = Grapheme;
0098 std::array<quint8, sizeof(void *) - 2> reserved = {};
0099 #endif
0100 };
0101
0102 Q_DECLARE_SHARED(QTextBoundaryFinder)
0103
0104 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextBoundaryFinder::BoundaryReasons)
0105
0106 QT_END_NAMESPACE
0107
0108 #endif
0109