Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Network
libktorrent
Commits
b8ef3422
Commit
b8ef3422
authored
Jul 24, 2022
by
Nicolas Fella
Browse files
Port away from QRegExp
parent
1994e46a
Pipeline
#208536
failed with stage
in 1 minute and 58 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/magnet/magnetlink.cpp
View file @
b8ef3422
...
...
@@ -5,6 +5,7 @@
*/
#include
"magnetlink.h"
#include
<QRegularExpression>
#include
<QStringList>
#include
<QUrlQuery>
#include
<util/error.h>
...
...
@@ -78,14 +79,17 @@ void MagnetLink::parse(const QUrl &url)
path
=
QUrlQuery
(
url
).
queryItemValue
(
QStringLiteral
(
"pt"
));
if
(
path
.
isEmpty
()
&&
url
.
path
()
!=
QLatin1String
(
"/"
))
{
// TODO find out why RemoveTrailingSlash does not work
path
=
url
.
adjusted
(
QUrl
::
StripTrailingSlash
).
path
().
remove
(
QReg
Exp
(
QLatin1String
(
"^/"
)));
path
=
url
.
adjusted
(
QUrl
::
StripTrailingSlash
).
path
().
remove
(
QReg
ularExpression
(
QLatin1String
(
"^/"
)));
}
QString
xt
=
QUrlQuery
(
url
).
queryItemValue
(
QLatin1String
(
"xt"
));
if
(
xt
.
isEmpty
()
||
!
xt
.
startsWith
(
QLatin1String
(
"urn:btih:"
)))
{
QRegExp
btihHash
(
QLatin1String
(
"([^
\\
.]+).btih"
));
if
(
btihHash
.
indexIn
(
url
.
host
())
!=
-
1
)
{
QString
primaryHash
=
btihHash
.
cap
(
1
).
split
(
'-'
)[
0
];
static
QRegularExpression
btihHash
(
QLatin1String
(
"([^
\\
.]+).btih"
));
const
QRegularExpressionMatch
match
=
btihHash
.
match
(
url
.
host
());
if
(
match
.
hasMatch
())
{
QString
primaryHash
=
match
.
captured
(
1
).
split
(
'-'
)[
0
];
xt
=
QLatin1String
(
"urn:btih:"
)
+
primaryHash
;
}
else
{
Out
(
SYS_GEN
|
LOG_NOTICE
)
<<
"No hash found in magnet link "
<<
url
<<
endl
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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