LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
regexp.h
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
#pragma once
10
11
#include "
sllconfig.h
"
12
#include <memory>
13
#include <QString>
14
#include <QMetaType>
15
#include <QRegularExpression>
16
#include "
visitor.h
"
17
18
namespace
LC::Util
19
{
20
// TODO mark this deprecated once Qt6 port is complete
21
class
UTIL_SLL_API
RegExp
22
{
23
QRegularExpression Rx_;
24
public
:
25
static
bool
IsFast
();
26
27
RegExp
() =
default
;
28
RegExp
(
const
QString&, Qt::CaseSensitivity);
29
30
bool
Matches
(
const
QString&)
const
;
31
bool
Matches
(
const
QByteArray&)
const
;
32
33
QString
GetPattern
()
const
;
34
Qt::CaseSensitivity
GetCaseSensitivity
()
const
;
35
};
36
37
struct
StopReplace
{};
38
39
struct
ReplaceAdvance
40
{
41
qsizetype
Shift_
;
42
43
explicit
ReplaceAdvance
(qsizetype shift)
44
:
Shift_
{ std::max<qsizetype> (shift, 1) }
45
{
46
}
47
};
48
49
using
ReplacerResult
= std::variant<StopReplace, ReplaceAdvance>;
50
51
template
<
typename
R>
52
void
ReplaceByRegexp
(QString& body,
53
const
QRegularExpression& rx,
54
R&& replacer)
55
requires
requires
{ { replacer (body, QRegularExpressionMatch {}) } -> std::convertible_to<ReplacerResult>; }
56
{
57
int
pos = 0;
58
bool
keepGoing =
true
;
59
while
(keepGoing)
60
{
61
const
auto
& match = rx.match (body, pos);
62
if
(!match.hasMatch ())
63
return
;
64
65
Util::Visit
(
ReplacerResult
{ replacer (body, match) },
66
[&] (StopReplace) { keepGoing =
false
; },
67
[&] (
ReplaceAdvance
adv) { pos = match.capturedStart (0) + adv.Shift_; });
68
}
69
}
70
}
71
72
UTIL_SLL_API
QDataStream&
operator<<
(QDataStream&,
const
LC::Util::RegExp
&);
73
UTIL_SLL_API
QDataStream&
operator>>
(QDataStream&,
LC::Util::RegExp
&);
74
75
Q_DECLARE_METATYPE
(
LC::Util::RegExp
)
LC::Util::RegExp
Definition
regexp.h:22
LC::Util::RegExp::GetPattern
QString GetPattern() const
Definition
regexp.cpp:48
LC::Util::RegExp::GetCaseSensitivity
Qt::CaseSensitivity GetCaseSensitivity() const
Definition
regexp.cpp:53
LC::Util::RegExp::RegExp
RegExp()=default
LC::Util::RegExp::Matches
bool Matches(const QString &) const
Definition
regexp.cpp:38
LC::Util::RegExp::IsFast
static bool IsFast()
Definition
regexp.cpp:26
LC::Util
Definition
icoreproxy.h:34
LC::Util::ReplacerResult
std::variant< StopReplace, ReplaceAdvance > ReplacerResult
Definition
regexp.h:49
LC::Util::ReplaceByRegexp
void ReplaceByRegexp(QString &body, const QRegularExpression &rx, R &&replacer)
Definition
regexp.h:52
LC::Util::Visit
auto Visit(const Either< Left, Right > &either, Args &&... args)
Definition
either.h:180
operator>>
UTIL_SLL_API QDataStream & operator>>(QDataStream &, LC::Util::RegExp &)
Definition
regexp.cpp:69
operator<<
UTIL_SLL_API QDataStream & operator<<(QDataStream &, const LC::Util::RegExp &)
Definition
regexp.cpp:61
sllconfig.h
UTIL_SLL_API
#define UTIL_SLL_API
Definition
sllconfig.h:16
LC::Util::ReplaceAdvance
Definition
regexp.h:40
LC::Util::ReplaceAdvance::ReplaceAdvance
ReplaceAdvance(qsizetype shift)
Definition
regexp.h:43
LC::Util::ReplaceAdvance::Shift_
qsizetype Shift_
Definition
regexp.h:41
LC::Util::StopReplace
Definition
regexp.h:37
visitor.h
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QVariantList *)
src
util
sll
regexp.h
Generated by
1.17.0