| 1 | /* This file is part of the KDE libraries |
| 2 | SPDX-FileCopyrightText: 2006 Jacob R Rideout <kde@jacobrideout.net> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef TEXTBREAKS_H |
| 8 | #define TEXTBREAKS_H |
| 9 | |
| 10 | class QString; |
| 11 | |
| 12 | #include "sonnetcore_export.h" |
| 13 | |
| 14 | #include <QList> |
| 15 | |
| 16 | #include <memory> |
| 17 | |
| 18 | namespace Sonnet |
| 19 | { |
| 20 | class TextBreaksPrivate; |
| 21 | |
| 22 | /*! |
| 23 | * \internal |
| 24 | * |
| 25 | * \brief TextBreaks determines the barriers between linguistic structures in any given text. |
| 26 | * |
| 27 | * TextBreaks is a class that determines the boundaries between graphemes |
| 28 | * (characters as per the unicode definition,) words and sentences. The |
| 29 | * default implementation conforms to Unicode Standard Annex #29 https://unicode.org/reports/tr29/. |
| 30 | * You can subclass TextBreaks to create the correct behaviour for languages that require it. |
| 31 | * |
| 32 | * \since 4.3 |
| 33 | */ |
| 34 | class SONNETCORE_EXPORT TextBreaks |
| 35 | { |
| 36 | public: |
| 37 | struct Position { |
| 38 | int start, length; |
| 39 | }; |
| 40 | |
| 41 | /*! |
| 42 | * \brief This structure abstracts the positions of breaks in the test. As per the |
| 43 | * unicode annex, both the start and end of the text are returned. |
| 44 | */ |
| 45 | typedef QList<Position> Positions; |
| 46 | |
| 47 | /*! Constructor |
| 48 | * Creates a new TextBreaks instance. If \a text is specified, |
| 49 | * it sets the text to be checked. |
| 50 | * \a text the text that is to be checked |
| 51 | */ |
| 52 | explicit TextBreaks(const QString &text = QString()); |
| 53 | |
| 54 | /*! Virtual Destructor |
| 55 | */ |
| 56 | virtual ~TextBreaks(); |
| 57 | |
| 58 | /*! |
| 59 | * Returns the text to be checked |
| 60 | * Returns text |
| 61 | */ |
| 62 | QString text() const; |
| 63 | |
| 64 | /*! |
| 65 | * Sets the text to \a text |
| 66 | * \a text to be set |
| 67 | * Returns true if the word is misspelled. false otherwise |
| 68 | */ |
| 69 | void setText(const QString &text); |
| 70 | |
| 71 | /*! |
| 72 | * Return the Positions of each word for the given \a text. |
| 73 | * \a text to be checked |
| 74 | * Returns positions of breaks |
| 75 | */ |
| 76 | static Positions wordBreaks(const QString &text); |
| 77 | |
| 78 | /*! |
| 79 | * Return the Positions of each sentence for the given \a text. |
| 80 | * \a text to be checked |
| 81 | * Returns positions of breaks |
| 82 | */ |
| 83 | static Positions sentenceBreaks(const QString &text); |
| 84 | |
| 85 | /*! |
| 86 | * Return the Positions of each word for the text previously set. |
| 87 | * Returns positions of breaks |
| 88 | */ |
| 89 | virtual Positions wordBreaks() const; |
| 90 | |
| 91 | /*! |
| 92 | * Return the Positions of each sentence for the text previously set. |
| 93 | * Returns positions of breaks |
| 94 | */ |
| 95 | virtual Positions sentenceBreaks() const; |
| 96 | |
| 97 | private: |
| 98 | std::unique_ptr<TextBreaksPrivate> const d; |
| 99 | }; |
| 100 | } |
| 101 | |
| 102 | Q_DECLARE_TYPEINFO(Sonnet::TextBreaks::Position, Q_PRIMITIVE_TYPE); |
| 103 | |
| 104 | #endif |
| 105 | |