LeechCraft  0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
regexp.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #include "regexp.h"
10 #include <QDataStream>
11 #include <QtDebug>
12 
13 namespace LC::Util
14 {
15  namespace
16  {
17  struct RegExpRegisterGuard
18  {
19  RegExpRegisterGuard ()
20  {
21  qRegisterMetaType<RegExp> ("Util::RegExp");
22  }
23  } Guard;
24  }
25 
27  {
28  return true;
29  }
30 
31  RegExp::RegExp (const QString& str, Qt::CaseSensitivity cs)
32  : Rx_ { str }
33  {
34  if (cs == Qt::CaseInsensitive)
35  Rx_.setPatternOptions (QRegularExpression::CaseInsensitiveOption);
36  }
37 
38  bool RegExp::Matches (const QString& str) const
39  {
40  return Rx_.match (str).hasMatch ();
41  }
42 
43  bool RegExp::Matches (const QByteArray& ba) const
44  {
45  return Rx_.match (ba).hasMatch ();
46  }
47 
48  QString RegExp::GetPattern () const
49  {
50  return Rx_.pattern ();
51  }
52 
53  Qt::CaseSensitivity RegExp::GetCaseSensitivity () const
54  {
55  return Rx_.patternOptions () & QRegularExpression::CaseInsensitiveOption ?
56  Qt::CaseInsensitive :
57  Qt::CaseSensitive;
58  }
59 }
60 
61 QDataStream& operator<< (QDataStream& out, const LC::Util::RegExp& rx)
62 {
63  out << static_cast<quint8> (1);
64  out << rx.GetPattern ()
65  << static_cast<quint8> (rx.GetCaseSensitivity ());
66  return out;
67 }
68 
69 QDataStream& operator>> (QDataStream& in, LC::Util::RegExp& rx)
70 {
71  quint8 version = 0;
72  in >> version;
73  if (version != 1)
74  {
75  qWarning () << Q_FUNC_INFO
76  << "unknown version"
77  << version;
78  return in;
79  }
80 
81  QString pattern;
82  quint8 cs;
83  in >> pattern
84  >> cs;
85 
86  rx = LC::Util::RegExp { pattern, static_cast<Qt::CaseSensitivity> (cs) };
87 
88  return in;
89 }
bool Matches(const QString &) const
Definition: regexp.cpp:38
QString GetPattern() const
Definition: regexp.cpp:48
QDataStream & operator>>(QDataStream &in, LC::Util::RegExp &rx)
Definition: regexp.cpp:69
RegExp()=default
static bool IsFast()
Definition: regexp.cpp:26
Qt::CaseSensitivity GetCaseSensitivity() const
Definition: regexp.cpp:53
QDataStream & operator<<(QDataStream &out, const LC::Util::RegExp &rx)
Definition: regexp.cpp:61