forked from qt-creator/qt-creator
Debugger: Escape special chars in line annotation
By re-using the existing function quoteUnprintable() and moving their code as escapeUnprintable() to watchutils. In contrast to the watches window, where the escaping can be disabled by the context menu, the line annotations are always escaped for simplicity. Change-Id: I76adfd7cd70ec92ff0d7f7ea41fc30ae0057cad0 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
4271b3a299
commit
a659f445c7
@@ -414,7 +414,7 @@ static void setValueAnnotationsHelper(BaseTextEditor *textEditor,
|
||||
const QString expression = expressionUnderCursor(tc);
|
||||
if (expression.isEmpty())
|
||||
continue;
|
||||
const QString value = values.take(expression); // Show value one only once.
|
||||
const QString value = escapeUnprintable(values.take(expression)); // Show value one only once.
|
||||
if (value.isEmpty())
|
||||
continue;
|
||||
const QString annotation = QString("%1: %2").arg(expression, value);
|
||||
|
||||
@@ -693,36 +693,7 @@ static QString reformatCharacter(int code, int size, bool isSigned)
|
||||
|
||||
static QString quoteUnprintable(const QString &str)
|
||||
{
|
||||
if (theUnprintableBase == 0)
|
||||
return str;
|
||||
|
||||
QString encoded;
|
||||
if (theUnprintableBase == -1) {
|
||||
for (const QChar c : str) {
|
||||
int u = c.unicode();
|
||||
if (c.isPrint())
|
||||
encoded += c;
|
||||
else if (u == '\r')
|
||||
encoded += "\\r";
|
||||
else if (u == '\t')
|
||||
encoded += "\\t";
|
||||
else if (u == '\n')
|
||||
encoded += "\\n";
|
||||
else
|
||||
encoded += QString("\\%1").arg(c.unicode(), 3, 8, QLatin1Char('0'));
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
for (const QChar c : str) {
|
||||
if (c.isPrint())
|
||||
encoded += c;
|
||||
else if (theUnprintableBase == 8)
|
||||
encoded += QString("\\%1").arg(c.unicode(), 3, 8, QLatin1Char('0'));
|
||||
else
|
||||
encoded += QString("\\u%1").arg(c.unicode(), 4, 16, QLatin1Char('0'));
|
||||
}
|
||||
return encoded;
|
||||
return escapeUnprintable(str, theUnprintableBase);
|
||||
}
|
||||
|
||||
static int itemFormat(const WatchItem *item)
|
||||
|
||||
@@ -242,5 +242,39 @@ QString formatToolTipAddress(quint64 a)
|
||||
return "0x" + rc;
|
||||
}
|
||||
|
||||
QString escapeUnprintable(const QString &str, int unprintableBase)
|
||||
{
|
||||
if (unprintableBase == 0)
|
||||
return str;
|
||||
|
||||
QString encoded;
|
||||
if (unprintableBase == -1) {
|
||||
for (const QChar c : str) {
|
||||
int u = c.unicode();
|
||||
if (c.isPrint())
|
||||
encoded += c;
|
||||
else if (u == '\r')
|
||||
encoded += "\\r";
|
||||
else if (u == '\t')
|
||||
encoded += "\\t";
|
||||
else if (u == '\n')
|
||||
encoded += "\\n";
|
||||
else
|
||||
encoded += QString("\\%1").arg(u, 3, 8, QLatin1Char('0'));
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
for (const QChar c : str) {
|
||||
if (c.isPrint())
|
||||
encoded += c;
|
||||
else if (unprintableBase == 8)
|
||||
encoded += QString("\\%1").arg(c.unicode(), 3, 8, QLatin1Char('0'));
|
||||
else
|
||||
encoded += QString("\\u%1").arg(c.unicode(), 4, 16, QLatin1Char('0'));
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Debugger
|
||||
|
||||
@@ -47,5 +47,7 @@ bool isIntType(const QString &type);
|
||||
QString formatToolTipAddress(quint64 a);
|
||||
QString removeObviousSideEffects(const QString &exp);
|
||||
|
||||
QString escapeUnprintable(const QString &str, int unprintableBase = -1);
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Debugger
|
||||
|
||||
Reference in New Issue
Block a user