forked from qt-creator/qt-creator
debugger: offer an option to show C-style escaped strings
Task-number: QTCREATORBUG-5667 Change-Id: I1c48fb19ece055c0b3a4b29ccee063cbce06f525 Reviewed-on: http://codereview.qt.nokia.com/2582 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -87,7 +87,7 @@ static QByteArray stripTemplate(const QByteArray &ba)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int m_unprintableBase = 8;
|
static int m_unprintableBase = -1;
|
||||||
|
|
||||||
void WatchHandler::setUnprintableBase(int base)
|
void WatchHandler::setUnprintableBase(int base)
|
||||||
{
|
{
|
||||||
@@ -364,7 +364,26 @@ static QString quoteUnprintable(const QString &str)
|
|||||||
{
|
{
|
||||||
if (WatchHandler::unprintableBase() == 0)
|
if (WatchHandler::unprintableBase() == 0)
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
QString encoded;
|
QString encoded;
|
||||||
|
if (WatchHandler::unprintableBase() == -1) {
|
||||||
|
foreach (const QChar c, str) {
|
||||||
|
int u = c.unicode();
|
||||||
|
if (u >= 32 && u < 127)
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (const QChar c, str) {
|
foreach (const QChar c, str) {
|
||||||
if (c.isPrint()) {
|
if (c.isPrint()) {
|
||||||
encoded += c;
|
encoded += c;
|
||||||
|
|||||||
@@ -645,6 +645,7 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
QAction *clearTypeFormatAction = 0;
|
QAction *clearTypeFormatAction = 0;
|
||||||
QAction *clearIndividualFormatAction = 0;
|
QAction *clearIndividualFormatAction = 0;
|
||||||
QAction *showUnprintableUnicode = 0;
|
QAction *showUnprintableUnicode = 0;
|
||||||
|
QAction *showUnprintableEscape = 0;
|
||||||
QAction *showUnprintableOctal = 0;
|
QAction *showUnprintableOctal = 0;
|
||||||
QAction *showUnprintableHexadecimal = 0;
|
QAction *showUnprintableHexadecimal = 0;
|
||||||
formatMenu.setTitle(tr("Change Display Format..."));
|
formatMenu.setTitle(tr("Change Display Format..."));
|
||||||
@@ -652,6 +653,10 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
formatMenu.addAction(tr("Treat All Characters as Printable"));
|
formatMenu.addAction(tr("Treat All Characters as Printable"));
|
||||||
showUnprintableUnicode->setCheckable(true);
|
showUnprintableUnicode->setCheckable(true);
|
||||||
showUnprintableUnicode->setChecked(unprintableBase == 0);
|
showUnprintableUnicode->setChecked(unprintableBase == 0);
|
||||||
|
showUnprintableEscape =
|
||||||
|
formatMenu.addAction(tr("Show Unprintable Characters as Escape Sequences"));
|
||||||
|
showUnprintableEscape->setCheckable(true);
|
||||||
|
showUnprintableEscape->setChecked(unprintableBase == -1);
|
||||||
showUnprintableOctal =
|
showUnprintableOctal =
|
||||||
formatMenu.addAction(tr("Show Unprintable Characters as Octal"));
|
formatMenu.addAction(tr("Show Unprintable Characters as Octal"));
|
||||||
showUnprintableOctal->setCheckable(true);
|
showUnprintableOctal->setCheckable(true);
|
||||||
@@ -932,6 +937,8 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
debuggerCore()->openTextEditor(tr("Locals & Watchers"), contents);
|
debuggerCore()->openTextEditor(tr("Locals & Watchers"), contents);
|
||||||
} else if (act == showUnprintableUnicode) {
|
} else if (act == showUnprintableUnicode) {
|
||||||
handler->setUnprintableBase(0);
|
handler->setUnprintableBase(0);
|
||||||
|
} else if (act == showUnprintableEscape) {
|
||||||
|
handler->setUnprintableBase(-1);
|
||||||
} else if (act == showUnprintableOctal) {
|
} else if (act == showUnprintableOctal) {
|
||||||
handler->setUnprintableBase(8);
|
handler->setUnprintableBase(8);
|
||||||
} else if (act == showUnprintableHexadecimal) {
|
} else if (act == showUnprintableHexadecimal) {
|
||||||
|
|||||||
@@ -1640,6 +1640,11 @@ void xxxx()
|
|||||||
|
|
||||||
void testQString()
|
void testQString()
|
||||||
{
|
{
|
||||||
|
QString str1("Hello Qt"); // --> Value: "Hello Qt"
|
||||||
|
QString str2("Hello\nQt"); // --> Value: ""Hello\nQt"" (double quote not expected)
|
||||||
|
QString str3("Hello\rQt"); // --> Value: ""HelloQt"" (double quote and missing \r not expected)
|
||||||
|
QString str4("Hello\tQt"); // --> Value: "Hello\9Qt" (expected \t instead of \9)
|
||||||
|
|
||||||
QString str = "Hello ";
|
QString str = "Hello ";
|
||||||
str += " big, ";
|
str += " big, ";
|
||||||
str += "\t";
|
str += "\t";
|
||||||
|
|||||||
Reference in New Issue
Block a user