pattern.h
1 //------------------------------------------------------------------------------
2 // pattern.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2021 Braden "Blzut3" Obrzut <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 
24 #ifndef PATTERN_H
25 #define PATTERN_H
26 
27 #include "dptr.h"
28 
29 #include <QRegularExpression>
30 
31 class QDataStream;
32 
38 class Pattern : public QRegularExpression
39 {
40  DPtr<Pattern> d;
41 
42  friend QDataStream &operator<<(QDataStream &out, const Pattern &re);
43  friend QDataStream &operator>>(QDataStream &in, Pattern &re);
44 
45 public:
46  enum Syntax
47  {
48  RegExp,
49  Wildcard
50  };
51 
52  Pattern();
53  Pattern(const Pattern &pattern);
54  Pattern(const QRegularExpression &re);
55  Pattern(const QString &pattern, QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption, Syntax syntax = RegExp);
56 
57  ~Pattern();
58 
59  QString userPattern() const;
60  void setUserPattern(const QString &pattern, Syntax syntax = RegExp);
61 
62 #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
63  static QString wildcardToRegularExpression(const QString &pattern)
64  {
65  return QRegularExpression::wildcardToRegularExpression(pattern);
66  }
67 #else
68  // Copy of Qt 5.15 version of this function is included in patternwildcard.cpp
69  static QString wildcardToRegularExpression(const QString &pattern);
70 #endif
71 };
72 
73 QDataStream &operator<<(QDataStream &out, const Pattern &re);
74 QDataStream &operator>>(QDataStream &in, Pattern &re);
75 
76 Q_DECLARE_METATYPE(Pattern);
77 
78 #endif