diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-03-27 13:41:02 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-04-01 10:29:26 +0200 |
commit | ef0f1429aeeecc7f897d102f80a992fc31e327a7 (patch) | |
tree | 2fceb779e36aee3f3a96c8dad1429d29ddf45aba /src/gui | |
parent | 70beac08afaec0ef0c4ef2e72ebfc007acba7d56 (diff) |
Remove QRegExp based API and QRegExp usage from QTextDocument
Change-Id: Ib5cc2d747f215a483585b703f9b4f6415e0d59f7
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 137 | ||||
-rw-r--r-- | src/gui/text/qtextdocument.h | 5 |
2 files changed, 8 insertions, 134 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index ab18fccee2..2b712c54b0 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -47,7 +47,6 @@ #include "qtexttable.h" #include "qtextlist.h" #include <qdebug.h> -#include <qregexp.h> #if QT_CONFIG(regularexpression) #include <qregularexpression.h> #endif @@ -1422,130 +1421,6 @@ QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &cur return find(subString, pos, options); } - -#ifndef QT_NO_REGEXP -static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int offset, - QTextDocument::FindFlags options, QTextCursor *cursor) -{ - QRegExp expr(expression); - QString text = block.text(); - text.replace(QChar::Nbsp, QLatin1Char(' ')); - - int idx = -1; - while (offset >=0 && offset <= text.length()) { - idx = (options & QTextDocument::FindBackward) ? - expr.lastIndexIn(text, offset) : expr.indexIn(text, offset); - if (idx == -1) - return false; - - if (options & QTextDocument::FindWholeWords) { - const int start = idx; - const int end = start + expr.matchedLength(); - if ((start != 0 && text.at(start - 1).isLetterOrNumber()) - || (end != text.length() && text.at(end).isLetterOrNumber())) { - //if this is not a whole word, continue the search in the string - offset = (options & QTextDocument::FindBackward) ? idx-1 : end+1; - idx = -1; - continue; - } - } - //we have a hit, return the cursor for that. - *cursor = QTextCursorPrivate::fromPosition(const_cast<QTextDocumentPrivate *>(QTextDocumentPrivate::get(block)), - block.position() + idx); - cursor->setPosition(cursor->position() + expr.matchedLength(), QTextCursor::KeepAnchor); - return true; - } - return false; -} - -/*! - \overload - - Finds the next occurrence that matches the given regular expression, - \a expr, within the same paragraph in the document. - - The search starts at the given \a from position, and proceeds forwards - through the document unless specified otherwise in the search options. - The \a options control the type of search performed. The FindCaseSensitively - option is ignored for this overload, use QRegExp::caseSensitivity instead. - - Returns a cursor with the match selected if a match was found; otherwise - returns a null cursor. - - If the \a from position is 0 (the default) the search begins from the beginning - of the document; otherwise it begins at the specified position. -*/ -QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags options) const -{ - Q_D(const QTextDocument); - - if (expr.isEmpty()) - return QTextCursor(); - - int pos = from; - //the cursor is positioned between characters, so for a backward search - //do not include the character given in the position. - if (options & FindBackward) { - --pos ; - if(pos < 0) - return QTextCursor(); - } - - QTextCursor cursor; - QTextBlock block = d->blocksFind(pos); - int blockOffset = pos - block.position(); - if (!(options & FindBackward)) { - while (block.isValid()) { - if (findInBlock(block, expr, blockOffset, options, &cursor)) - return cursor; - block = block.next(); - blockOffset = 0; - } - } else { - while (block.isValid()) { - if (findInBlock(block, expr, blockOffset, options, &cursor)) - return cursor; - block = block.previous(); - blockOffset = block.length() - 1; - } - } - - return QTextCursor(); -} - -/*! - \overload - - Finds the next occurrence that matches the given regular expression, - \a expr, within the same paragraph in the document. - - The search starts at the position of the given from \a cursor, and proceeds - forwards through the document unless specified otherwise in the search - options. The \a options control the type of search performed. The FindCaseSensitively - option is ignored for this overload, use QRegExp::caseSensitivity instead. - - Returns a cursor with the match selected if a match was found; otherwise - returns a null cursor. - - If the given \a cursor has a selection, the search begins after the - selection; otherwise it begins at the cursor's position. - - By default the search is case insensitive, and can match text anywhere in the - document. -*/ -QTextCursor QTextDocument::find(const QRegExp &expr, const QTextCursor &cursor, FindFlags options) const -{ - int pos = 0; - if (!cursor.isNull()) { - if (options & QTextDocument::FindBackward) - pos = cursor.selectionStart(); - else - pos = cursor.selectionEnd(); - } - return find(expr, pos, options); -} -#endif // QT_REGEXP - #if QT_CONFIG(regularexpression) static bool findInBlock(const QTextBlock &block, const QRegularExpression &expr, int offset, QTextDocument::FindFlags options, QTextCursor *cursor) @@ -2283,7 +2158,11 @@ static QString colorValue(QColor color) if (color.alpha() == 255) { result = color.name(); } else if (color.alpha()) { - QString alphaValue = QString::number(color.alphaF(), 'f', 6).remove(QRegExp(QLatin1String("\\.?0*$"))); + QString alphaValue = QString::number(color.alphaF(), 'f', 6); + while (alphaValue.length() > 1 && alphaValue.at(alphaValue.size() - 1) == QLatin1Char('0')) + alphaValue.chop(1); + if (alphaValue.at(alphaValue.size() - 1) == QLatin1Char('.')) + alphaValue.chop(1); result = QString::fromLatin1("rgba(%1,%2,%3,%4)").arg(color.red()) .arg(color.green()) .arg(color.blue()) @@ -2786,10 +2665,10 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) txt = txt.toHtmlEscaped(); // split for [\n{LineSeparator}] - QString forcedLineBreakRegExp = QString::fromLatin1("[\\na]"); - forcedLineBreakRegExp[3] = QChar::LineSeparator; // space in BR on purpose for compatibility with old-fashioned browsers - html += txt.replace(QRegExp(forcedLineBreakRegExp), QLatin1String("<br />")); + txt.replace(QLatin1Char('\n'), QLatin1String("<br />")); + txt.replace(QChar::LineSeparator, QLatin1String("<br />")); + html += txt; } if (attributesEmitted) diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h index 1a1a3da8e8..5a165331bf 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -186,11 +186,6 @@ public: QTextCursor find(const QString &subString, int from = 0, FindFlags options = FindFlags()) const; QTextCursor find(const QString &subString, const QTextCursor &cursor, FindFlags options = FindFlags()) const; -#ifndef QT_NO_REGEXP - QTextCursor find(const QRegExp &expr, int from = 0, FindFlags options = FindFlags()) const; - QTextCursor find(const QRegExp &expr, const QTextCursor &cursor, FindFlags options = FindFlags()) const; -#endif - #if QT_CONFIG(regularexpression) QTextCursor find(const QRegularExpression &expr, int from = 0, FindFlags options = FindFlags()) const; QTextCursor find(const QRegularExpression &expr, const QTextCursor &cursor, FindFlags options = FindFlags()) const; |