File indexing completed on 2024-04-21 03:57:39
0001 /* 0002 SPDX-FileCopyrightText: 2009-2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 0003 SPDX-FileCopyrightText: 2007 Sebastian Pipping <webmaster@hartwork.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef _KATE_PLAINTEXTSEARCH_H_ 0009 #define _KATE_PLAINTEXTSEARCH_H_ 0010 0011 #include <QObject> 0012 0013 #include <ktexteditor/range.h> 0014 0015 #include <ktexteditor_export.h> 0016 0017 namespace KTextEditor 0018 { 0019 class Document; 0020 } 0021 0022 /** 0023 * Object to help to search for plain text. 0024 * This should be NO QObject, it is created too often! 0025 * I measured that, if you create it 20k times to replace for example " " in a document, that takes seconds on a modern machine! 0026 */ 0027 class KTEXTEDITOR_EXPORT KatePlainTextSearch 0028 { 0029 public: 0030 explicit KatePlainTextSearch(const KTextEditor::Document *document, Qt::CaseSensitivity caseSensitivity, bool wholeWords); 0031 ~KatePlainTextSearch() = default; 0032 0033 public: 0034 /** 0035 * Search for the given \p text inside the range \p inputRange taking 0036 * into account whether to search \p casesensitive and \p backwards. 0037 * 0038 * \param text text to search for 0039 * \param inputRange Range to search in 0040 * \param backwards if \e true, the search will be backwards 0041 * \return The valid range of the matched text if \p text was found. If 0042 * the \p text was not found, the returned range is not valid 0043 * (see Range::isValid()). 0044 * \see KTextEditor::Range 0045 */ 0046 KTextEditor::Range search(const QString &text, KTextEditor::Range inputRange, bool backwards = false); 0047 0048 private: 0049 const KTextEditor::Document *m_document; 0050 Qt::CaseSensitivity m_caseSensitivity; 0051 bool m_wholeWords; 0052 }; 0053 0054 #endif