1 /*************************************************************************** 2 * Copyright (C) 2004-2021 by Pere Constans 3 * constans@molspaces.com 4 * cb2Bib version 2.0.1. Licensed under the GNU GPL version 3. 5 * See the LICENSE file that comes with this distribution. 6 ***************************************************************************/ 7 #ifndef COMPOSITEPATTERN_H 8 #define COMPOSITEPATTERN_H 9 10 #include <QRegularExpression> 11 #include <QStringList> 12 #include <QVector> 13 14 15 class compositePattern 16 { 17 18 public: 19 compositePattern(); 20 compositePattern(const QString& pattern, const Qt::CaseSensitivity cs); 21 inline virtual ~compositePattern() {} 22 23 24 inline const QString strings() const 25 { 26 return _string; 27 } 28 inline const QStringList substrings() const 29 { 30 return _substrings; 31 } 32 inline const QRegularExpression& regexp() const 33 { 34 return _regexp; 35 } 36 inline const QVector<QRegularExpression>& subregexps() const 37 { 38 return _subregexps; 39 } 40 inline Qt::CaseSensitivity caseSensitivity() const 41 { 42 return _case_sensitivity; 43 } 44 inline int subpatternCount() const 45 { 46 return _subpattern_count; 47 } 48 inline int matchedLength() const 49 { 50 return _matched_length; 51 } 52 inline bool isMultipattern() const 53 { 54 return _is_multipattern; 55 } 56 57 virtual bool matches(const QString& str) const = 0; 58 virtual int indexIn(const QString& str, const int from) const = 0; 59 60 61 protected: 62 static QString escape(const QString& str, const Qt::CaseSensitivity cs); 63 void set_sort_index(); 64 65 QList<double> _ranks; 66 QRegularExpression _regexp; 67 QString _string; 68 QStringList _substrings; 69 QVector<QRegularExpression> _subregexps; 70 QVector<int> _index; 71 Qt::CaseSensitivity _case_sensitivity; 72 bool _is_multipattern; 73 int _subpattern_count; 74 mutable QVector<int> _p0; 75 mutable QVector<int> _pn; 76 mutable int _matched_length; 77 }; 78 79 #endif