summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2011-09-29 13:31:39 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-29 15:22:07 +0200
commitb863df7de926448cf0057272c16da04b7cfb11ee (patch)
tree378b951c3ad748bcb6250d8d33d9be55494933e2 /src
parent7fb90066b3aa7e602466a61e0ffaadbf9002525c (diff)
Rename Qt::escape to QString::toHtmlEscaped, add compat method
Merge-request: 56 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com> Change-Id: I46bbb2df10968e88b5eb5ef8dae182a651b622b8 Reviewed-on: http://codereview.qt-project.org/5793 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qstring.cpp31
-rw-r--r--src/corelib/tools/qstring.h7
-rw-r--r--src/gui/text/qtextdocument.cpp10
3 files changed, 29 insertions, 19 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 37f8554381..c22c8a9edd 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -8788,6 +8788,14 @@ QVector<uint> QStringRef::toUcs4() const
return v;
}
+
+/*!
+ \obsolete
+ \fn QString Qt::escape(const QString &plain)
+
+ \sa QString::toHtmlEscaped()
+*/
+
/*!
Converts the plain text string \a plain to a HTML string with
HTML metacharacters \c{<}, \c{>}, \c{&}, and \c{"} replaced by HTML
@@ -8795,27 +8803,24 @@ QVector<uint> QStringRef::toUcs4() const
Example:
- \snippet doc/src/snippets/code/src_gui_text_qtextdocument.cpp 0
-
- This function is defined in the \c <QString> header file.
-
- \sa convertFromPlainText(), mightBeRichText()
+ \snippet doc/src/snippets/code/src_corelib_tools_qstring.cpp 7
*/
-QString Qt::escape(const QString &plain)
+QString QString::toHtmlEscaped() const
{
QString rich;
- rich.reserve(int(plain.length() * 1.1));
- for (int i = 0; i < plain.length(); ++i) {
- if (plain.at(i) == QLatin1Char('<'))
+ const int len = length();
+ rich.reserve(int(len * 1.1));
+ for (int i = 0; i < len; ++i) {
+ if (at(i) == QLatin1Char('<'))
rich += QLatin1String("&lt;");
- else if (plain.at(i) == QLatin1Char('>'))
+ else if (at(i) == QLatin1Char('>'))
rich += QLatin1String("&gt;");
- else if (plain.at(i) == QLatin1Char('&'))
+ else if (at(i) == QLatin1Char('&'))
rich += QLatin1String("&amp;");
- else if (plain.at(i) == QLatin1Char('"'))
+ else if (at(i) == QLatin1Char('"'))
rich += QLatin1String("&quot;");
else
- rich += plain.at(i);
+ rich += at(i);
}
rich.squeeze();
return rich;
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index adb7e06ce1..b73a34a2a0 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -330,6 +330,7 @@ public:
QString trimmed() const Q_REQUIRED_RESULT;
QString simplified() const Q_REQUIRED_RESULT;
+ QString toHtmlEscaped() const Q_REQUIRED_RESULT;
QString &insert(int i, QChar c);
QString &insert(int i, const QChar *uc, int len);
@@ -1250,7 +1251,11 @@ inline QBool QStringRef::contains(const QStringRef &s, Qt::CaseSensitivity cs) c
{ return QBool(indexOf(s, 0, cs) != -1); }
namespace Qt {
- Q_CORE_EXPORT QString escape(const QString &plain);
+#if QT_DEPRECATED_SINCE(5, 0)
+QT_DEPRECATED inline QString escape(const QString &plain) {
+ return plain.toHtmlEscaped();
+}
+#endif
}
QT_END_NAMESPACE
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index c44e98b77e..8d9a8c405a 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -2087,7 +2087,7 @@ void QTextHtmlExporter::emitAttribute(const char *attribute, const QString &valu
html += QLatin1Char(' ');
html += QLatin1String(attribute);
html += QLatin1String("=\"");
- html += Qt::escape(value);
+ html += value.toHtmlEscaped();
html += QLatin1Char('"');
}
@@ -2360,7 +2360,7 @@ void QTextHtmlExporter::emitFontFamily(const QString &family)
quote = QLatin1String("&quot;");
html += quote;
- html += Qt::escape(family);
+ html += family.toHtmlEscaped();
html += quote;
html += QLatin1Char(';');
}
@@ -2394,13 +2394,13 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment)
const QString name = format.anchorName();
if (!name.isEmpty()) {
html += QLatin1String("<a name=\"");
- html += Qt::escape(name);
+ html += name.toHtmlEscaped();
html += QLatin1String("\"></a>");
}
const QString href = format.anchorHref();
if (!href.isEmpty()) {
html += QLatin1String("<a href=\"");
- html += Qt::escape(href);
+ html += href.toHtmlEscaped();
html += QLatin1String("\">");
closeAnchor = true;
}
@@ -2449,7 +2449,7 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment)
} else {
Q_ASSERT(!txt.contains(QChar::ObjectReplacementCharacter));
- txt = Qt::escape(txt);
+ txt = txt.toHtmlEscaped();
// split for [\n{LineSeparator}]
QString forcedLineBreakRegExp = QString::fromLatin1("[\\na]");