Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Akregator
Commits
2651f965
Commit
2651f965
authored
Aug 01, 2020
by
Ahmad Samir
Committed by
Volker Krause
Aug 15, 2020
Browse files
Port QRegExp to QRegularExpression
parent
9361363e
Pipeline
#30731
passed with stage
in 18 minutes and 47 seconds
Changes
3
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
src/article.cpp
View file @
2651f965
...
...
@@ -18,7 +18,7 @@
#include <QDateTime>
#include <qdom.h>
#include <QReg
Exp
>
#include <QReg
ularExpression
>
#include <QList>
#include "akregator_debug.h"
...
...
@@ -39,19 +39,32 @@ QString buildTitle(const QString &description)
if
(
i
!=
-
1
)
{
s
=
s
.
left
(
i
+
1
);
}
QRegExp
rx
(
QStringLiteral
(
"(<([^
\\
s>]*)(?:[^>]*)>)[^<]*"
),
Qt
::
CaseInsensitive
);
QString
tagName
,
toReplace
,
replaceWith
;
while
(
rx
.
indexIn
(
s
)
!=
-
1
)
{
tagName
=
rx
.
cap
(
2
);
if
(
tagName
==
QLatin1String
(
"SCRIPT"
)
||
tagName
==
QLatin1String
(
"script"
))
{
toReplace
=
rx
.
cap
(
0
);
// strip tag AND tag contents
}
else
if
(
tagName
.
startsWith
(
QLatin1String
(
"br"
))
||
tagName
.
startsWith
(
QLatin1String
(
"BR"
)))
{
toReplace
=
rx
.
cap
(
1
);
const
QRegularExpression
rx
(
QStringLiteral
(
"(<([^
\\
s>]*)(?:[^>]*)>)[^<]*"
));
int
offset
=
0
;
QRegularExpressionMatch
rmatch
;
// We get the opening tag (e.g. <i>) in one iteration and then the closing
// tag (e.g. </i>), in the next one. Note that <br> doesn't have a closing tag
while
(
s
.
indexOf
(
rx
,
offset
,
&
rmatch
)
!=
-
1
)
{
const
QString
tagName
=
rmatch
.
captured
(
2
);
QString
toReplace
;
QString
replaceWith
;
int
repStart
=
0
;
if
(
tagName
.
compare
(
QLatin1String
(
"script"
),
Qt
::
CaseInsensitive
)
==
0
)
{
// E.g.: <script foo="bar">some js here</script>
// strip tag AND tag contents
toReplace
=
rmatch
.
captured
(
0
);
repStart
=
rmatch
.
capturedStart
(
0
);
}
else
if
(
tagName
.
startsWith
(
QLatin1String
(
"br"
),
Qt
::
CaseInsensitive
))
{
toReplace
=
rmatch
.
captured
(
1
);
repStart
=
rmatch
.
capturedStart
(
1
);
replaceWith
=
QLatin1Char
(
' '
);
}
else
{
toReplace
=
rx
.
cap
(
1
);
// strip just tag
// Any other tag, <i>text</i> ... etc
toReplace
=
rmatch
.
captured
(
1
);
// strip just tag
repStart
=
rmatch
.
capturedStart
(
1
);
}
s
.
replace
(
s
.
indexOf
(
toReplace
),
toReplace
.
length
(),
replaceWith
);
// do the deed
s
.
replace
(
repStart
,
toReplace
.
length
(),
replaceWith
);
// do the deed
offset
=
repStart
+
replaceWith
.
length
();
}
if
(
s
.
length
()
>
90
)
{
s
=
s
.
left
(
90
)
+
QLatin1String
(
"..."
);
...
...
src/articlematcher.cpp
View file @
2651f965
...
...
@@ -13,7 +13,7 @@
#include <KConfigGroup>
#include "akregator_debug.h"
#include <QReg
Exp
>
#include <QReg
ularExpression
>
namespace
Akregator
{
namespace
Filters
{
...
...
@@ -174,7 +174,7 @@ bool Criterion::satisfiedBy(const Article &article) const
}
break
;
case
Matches
:
satisfied
=
QRegExp
(
m_o
bject
.
toString
()
).
indexIn
(
concreteSu
bject
.
toString
())
!=
-
1
;
satisfied
=
concreteSu
bject
.
toString
()
.
contains
(
QRegularExpression
(
m_o
bject
.
toString
())
)
;
break
;
default:
qCDebug
(
AKREGATOR_LOG
)
<<
"Internal inconsistency; predicateType should never be Negation"
;
...
...
src/utils.cpp
View file @
2651f965
...
...
@@ -7,7 +7,7 @@
*/
#include "utils.h"
#include <QReg
Exp
>
#include <QReg
ularExpression
>
#include <QString>
#include <QTextDocument>
...
...
@@ -21,7 +21,7 @@ QString Utils::convertHtmlTags(const QString &title)
QString
Utils
::
stripTags
(
QString
str
)
{
return
str
.
remove
(
QReg
Exp
(
QLatin1String
(
"<[^>]*>"
)));
return
str
.
remove
(
QReg
ularExpression
(
QStringLiteral
(
"<[^>]*>"
)));
}
uint
Utils
::
calcHash
(
const
QString
&
str
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment