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
PIM
PIM Messagelib
Commits
8de035f3
Commit
8de035f3
authored
Oct 12, 2022
by
Volker Krause
Committed by
Laurent Montel
Oct 12, 2022
Browse files
Port to QRegularExpression
parent
fc60dd3d
Pipeline
#246569
passed with stage
in 9 minutes and 48 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
messagecomposer/src/composer-ng/richtextcomposersignatures.cpp
View file @
8de035f3
...
...
@@ -9,6 +9,7 @@
#include
<KIdentityManagement/Signature>
#include
<QRegularExpression>
#include
<QTextBlock>
using
namespace
MessageComposer
;
...
...
@@ -20,7 +21,7 @@ public:
{
}
void
cleanWhitespaceHelper
(
const
QReg
Exp
&
regExp
,
const
QString
&
newText
,
const
KIdentityManagement
::
Signature
&
sig
);
void
cleanWhitespaceHelper
(
const
QReg
ularExpression
&
regExp
,
const
QString
&
newText
,
const
KIdentityManagement
::
Signature
&
sig
);
Q_REQUIRED_RESULT
QVector
<
QPair
<
int
,
int
>>
signaturePositions
(
const
KIdentityManagement
::
Signature
&
sig
)
const
;
RichTextComposerNg
*
const
richTextComposer
;
};
...
...
@@ -33,7 +34,7 @@ RichTextComposerSignatures::RichTextComposerSignatures(MessageComposer::RichText
RichTextComposerSignatures
::~
RichTextComposerSignatures
()
=
default
;
void
RichTextComposerSignatures
::
RichTextComposerSignaturesPrivate
::
cleanWhitespaceHelper
(
const
QReg
Exp
&
regExp
,
void
RichTextComposerSignatures
::
RichTextComposerSignaturesPrivate
::
cleanWhitespaceHelper
(
const
QReg
ularExpression
&
regExp
,
const
QString
&
newText
,
const
KIdentityManagement
::
Signature
&
sig
)
{
...
...
@@ -42,19 +43,19 @@ void RichTextComposerSignatures::RichTextComposerSignaturesPrivate::cleanWhitesp
for
(;;)
{
// Find the text
const
QString
text
=
richTextComposer
->
document
()
->
toPlainText
();
const
int
currentMatch
=
regExp
.
indexIn
(
text
,
currentSearchPosition
);
currentSearchPosition
=
currentMatch
;
if
(
currentMatch
==
-
1
)
{
const
auto
currentMatch
=
regExp
.
match
(
text
,
currentSearchPosition
);
if
(
!
currentMatch
.
hasMatch
())
{
break
;
}
currentSearchPosition
=
currentMatch
.
capturedStart
();
// Select the text
QTextCursor
cursor
(
richTextComposer
->
document
());
cursor
.
setPosition
(
current
Match
);
cursor
.
movePosition
(
QTextCursor
::
NextCharacter
,
QTextCursor
::
KeepAnchor
,
regExp
.
match
edLength
());
cursor
.
setPosition
(
current
SearchPosition
);
cursor
.
movePosition
(
QTextCursor
::
NextCharacter
,
QTextCursor
::
KeepAnchor
,
currentMatch
.
captur
edLength
());
// Skip quoted text
if
(
richTextComposer
->
isLineQuoted
(
cursor
.
block
().
text
()))
{
currentSearchPosition
+=
regExp
.
match
edLength
();
currentSearchPosition
+=
currentMatch
.
captur
edLength
();
continue
;
}
// Skip text inside signatures
...
...
@@ -66,7 +67,7 @@ void RichTextComposerSignatures::RichTextComposerSignaturesPrivate::cleanWhitesp
}
}
if
(
insideSignature
)
{
currentSearchPosition
+=
regExp
.
match
edLength
();
currentSearchPosition
+=
currentMatch
.
captur
edLength
();
continue
;
}
...
...
@@ -83,13 +84,13 @@ void RichTextComposerSignatures::cleanWhitespace(const KIdentityManagement::Sign
cursor
.
beginEditBlock
();
// Squeeze tabs and spaces
d
->
cleanWhitespaceHelper
(
QReg
Exp
(
QLatin1String
(
"[
\t
]+"
)),
QStringLiteral
(
" "
),
sig
);
d
->
cleanWhitespaceHelper
(
QReg
ularExpression
(
QLatin1String
(
"[
\t
]+"
)),
QStringLiteral
(
" "
),
sig
);
// Remove trailing whitespace
d
->
cleanWhitespaceHelper
(
QReg
Exp
(
QLatin1String
(
"[
\t
][
\n
]"
)),
QStringLiteral
(
"
\n
"
),
sig
);
d
->
cleanWhitespaceHelper
(
QReg
ularExpression
(
QLatin1String
(
"[
\t
][
\n
]"
)),
QStringLiteral
(
"
\n
"
),
sig
);
// Single space lines
d
->
cleanWhitespaceHelper
(
QReg
Exp
(
QLatin1String
(
"[
\n
]{3,}"
)),
QStringLiteral
(
"
\n\n
"
),
sig
);
d
->
cleanWhitespaceHelper
(
QReg
ularExpression
(
QLatin1String
(
"[
\n
]{3,}"
)),
QStringLiteral
(
"
\n\n
"
),
sig
);
if
(
!
d
->
richTextComposer
->
textCursor
().
hasSelection
())
{
d
->
richTextComposer
->
textCursor
().
clearSelection
();
...
...
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