| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2009-2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de> |
| 3 | SPDX-FileCopyrightText: 2007 Sebastian Pipping <webmaster@hartwork.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #ifndef _KATE_PLAINTEXTSEARCH_H_ |
| 9 | #define _KATE_PLAINTEXTSEARCH_H_ |
| 10 | |
| 11 | #include <QObject> |
| 12 | |
| 13 | #include <ktexteditor/range.h> |
| 14 | |
| 15 | #include <ktexteditor_export.h> |
| 16 | |
| 17 | namespace KTextEditor |
| 18 | { |
| 19 | class Document; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Object to help to search for plain text. |
| 24 | * This should be NO QObject, it is created too often! |
| 25 | * I measured that, if you create it 20k times to replace for example " " in a document, that takes seconds on a modern machine! |
| 26 | */ |
| 27 | class KTEXTEDITOR_EXPORT KatePlainTextSearch |
| 28 | { |
| 29 | public: |
| 30 | explicit KatePlainTextSearch(const KTextEditor::Document *document, Qt::CaseSensitivity caseSensitivity, bool wholeWords); |
| 31 | ~KatePlainTextSearch() = default; |
| 32 | |
| 33 | public: |
| 34 | /** |
| 35 | * Search for the given \p text inside the range \p inputRange taking |
| 36 | * into account whether to search \p casesensitive and \p backwards. |
| 37 | * |
| 38 | * \param text text to search for |
| 39 | * \param inputRange Range to search in |
| 40 | * \param backwards if \e true, the search will be backwards |
| 41 | * \return The valid range of the matched text if \p text was found. If |
| 42 | * the \p text was not found, the returned range is not valid |
| 43 | * (see Range::isValid()). |
| 44 | * \see KTextEditor::Range |
| 45 | */ |
| 46 | KTextEditor::Range search(const QString &text, KTextEditor::Range inputRange, bool backwards = false); |
| 47 | |
| 48 | private: |
| 49 | const KTextEditor::Document *m_document; |
| 50 | Qt::CaseSensitivity m_caseSensitivity; |
| 51 | bool m_wholeWords; |
| 52 | }; |
| 53 | |
| 54 | #endif |
| 55 | |