Commit 4170e580 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Port one QRegExp to QRegularExpression

Make the pattern non-greedy to match the behaviour or

Don't iterate over the string manually,
QString::replace(QRegularExpression) will constructs a
QRegularExpressionMatchIterator internally and do that work.
parent 7e766d14
Pipeline #184159 passed with stage
in 6 minutes and 1 second
......@@ -21,7 +21,7 @@
#include <QColorDialog>
#include <QIcon>
#include <QPointer>
#include <QRegExp>
#include <QRegularExpression>
#include <QTextBlock>
#include <QTextDocumentFragment>
#include <QTextList>
......@@ -555,7 +555,7 @@ QString RichTextComposerControler::toCleanHtml() const
// Qt inserts various style properties based on the current mode of the editor (underline,
// bold, etc), but only empty paragraphs *also* have qt-paragraph-type set to 'empty'.
static const QString EMPTYLINEREGEX = QStringLiteral("<p style=\"-qt-paragraph-type:empty;(.*)</p>");
static const QRegularExpression EMPTYLINEREGEX(QStringLiteral("<p style=\"-qt-paragraph-type:empty;(.*?)</p>"));
static const QString OLLISTPATTERNQT = QStringLiteral("<ol style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px;");
......@@ -570,19 +570,8 @@ QString RichTextComposerControler::toCleanHtml() const
// Although we can simply remove the margin-top style property, we still get unwanted results
// if you have three or more empty lines. It's best to replace empty <p> elements with <p>&nbsp;</p>.
QRegExp emptyLineFinder(EMPTYLINEREGEX);
// find the first occurrence
int offset = emptyLineFinder.indexIn(result, 0);
while (offset != -1) {
// replace all the matching text with the new line text
result.replace(offset, emptyLineFinder.matchedLength(), EMPTYLINEHTML);
// advance the search offset to just beyond the last replace
offset += EMPTYLINEHTML.length();
// find the next occurrence
offset = emptyLineFinder.indexIn(result, offset);
// replace all the matching text with the new line text
// fix 2a - ordered lists - MS Outlook treats margin-left:0px; as
// a non-existing number; e.g: "1. First item" turns into "First Item"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment