File indexing completed on 2024-05-12 09:56:57
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0003 SPDX-FileCopyrightText: 2020 Tomaz Canabrava <tcanabrava@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef REGEXP_FILTER_H 0009 #define REGEXP_FILTER_H 0010 0011 #include "Filter.h" 0012 0013 #include "konsoleprivate_export.h" 0014 #include <QRegularExpression> 0015 #include <QSharedPointer> 0016 0017 namespace Konsole 0018 { 0019 class HotSpot; 0020 /** 0021 * A filter which searches for sections of text matching a regular expression and creates a new RegExpFilter::HotSpot 0022 * instance for them. 0023 * 0024 * Subclasses can reimplement newHotSpot() to return custom hotspot types when matches for the regular expression 0025 * are found. 0026 */ 0027 class KONSOLEPRIVATE_EXPORT RegExpFilter : public Filter 0028 { 0029 public: 0030 /** Constructs a new regular expression filter */ 0031 RegExpFilter(); 0032 0033 /** 0034 * Sets the regular expression which the filter searches for in blocks of text. 0035 * 0036 * Regular expressions which match the empty string are treated as not matching 0037 * anything. 0038 */ 0039 void setRegExp(const QRegularExpression ®Exp); 0040 /** Returns the regular expression which the filter searches for in blocks of text */ 0041 QRegularExpression regExp() const; 0042 0043 /** 0044 * Reimplemented to search the filter's text buffer for text matching regExp() 0045 * 0046 * If regexp matches the empty string, then process() will return immediately 0047 * without finding results. 0048 */ 0049 void process() override; 0050 0051 protected: 0052 /** 0053 * Called when a match for the regular expression is encountered. Subclasses should reimplement this 0054 * to return custom hotspot types 0055 */ 0056 virtual QSharedPointer<HotSpot> newHotSpot(int startLine, int startColumn, int endLine, int endColumn, const QStringList &capturedTexts); 0057 0058 private: 0059 QRegularExpression _searchText; 0060 }; 0061 0062 } 0063 #endif