45 #ifndef PCRE_STUDY_JIT_COMPILE
46 #define PCRE_STUDY_JIT_COMPILE 0
55 Qt::CaseSensitivity CS_;
63 PCREWrapper (
const QString& str, Qt::CaseSensitivity cs)
64 : RE_ (Compile (str, cs))
71 pcre_refcount (RE_, 1);
72 const char *error = 0;
73 const int opts = PCRE_STUDY_JIT_COMPILE;
74 Extra_ = pcre_study (RE_, opts, &error);
78 PCREWrapper (
const PCREWrapper& other)
85 PCREWrapper& operator= (
const PCREWrapper& other)
87 if (RE_ && !pcre_refcount (RE_, -1))
94 Extra_ = other.Extra_;
96 pcre_refcount (RE_, 1);
106 if (!pcre_refcount (RE_, -1))
113 const QString& GetPattern ()
const
118 Qt::CaseSensitivity GetCS ()
const
123 int Exec (
const QByteArray& utf8)
const
125 return RE_ ? pcre_exec (RE_, Extra_, utf8.constData (), utf8.size (), 0, 0, NULL, 0) : -1;
128 pcre* Compile (
const QString& str, Qt::CaseSensitivity cs)
130 const char *error = 0;
132 int options = PCRE_UTF8;
133 if (cs == Qt::CaseInsensitive)
134 options |= PCRE_CASELESS;
135 auto re = pcre_compile (str.toUtf8 ().constData (), options, &error, &errOffset, NULL);
137 qWarning () << Q_FUNC_INFO
138 <<
"failed compiling"
147 #ifdef PCRE_CONFIG_JIT
148 pcre_free_study (Extra_);
158 struct RegExpRegisterGuard
160 RegExpRegisterGuard ()
162 qRegisterMetaType<RegExp> (
"Util::RegExp");
163 qRegisterMetaTypeStreamOperators<RegExp> ();
190 : Impl_ {
new RegExpImpl { QRegExp { str, cs, QRegExp::RegExp } } }
201 return Impl_->PRx_.Exec (str.toUtf8 ()) >= 0;
203 return Impl_->Rx_.exactMatch (str);
213 return Impl_->PRx_.GetPattern ();
215 return Impl_->Rx_.pattern ();
225 return Impl_->PRx_.GetCS ();
227 return Impl_->Rx_.caseSensitivity ();
235 out << static_cast<quint8> (1);
247 qWarning () << Q_FUNC_INFO
Qt::CaseSensitivity GetCaseSensitivity() const
QString GetPattern() const
QDataStream & operator>>(QDataStream &in, LeechCraft::Util::RegExp &rx)
QDataStream & operator<<(QDataStream &out, const LeechCraft::Util::RegExp &rx)
bool Matches(const QString &) const