OSDN Git Service

debugger: offer an option to show C-style escaped strings
authorhjk <qtc-committer@nokia.com>
Wed, 3 Aug 2011 15:04:32 +0000 (17:04 +0200)
committerhjk <qthjk@ovi.com>
Wed, 3 Aug 2011 15:06:23 +0000 (17:06 +0200)
Task-number: QTCREATORBUG-5667
Change-Id: I1c48fb19ece055c0b3a4b29ccee063cbce06f525
Reviewed-on: http://codereview.qt.nokia.com/2582
Reviewed-by: hjk <qthjk@ovi.com>
src/plugins/debugger/watchhandler.cpp
src/plugins/debugger/watchwindow.cpp
tests/manual/gdbdebugger/simple/simple_gdbtest_app.cpp

index c860150..2624c79 100644 (file)
@@ -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)
 {
@@ -364,7 +364,26 @@ static QString quoteUnprintable(const QString &str)
 {
     if (WatchHandler::unprintableBase() == 0)
         return str;
+
     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) {
         if (c.isPrint()) {
             encoded += c;
index a03f016..8cf5060 100644 (file)
@@ -645,6 +645,7 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
     QAction *clearTypeFormatAction = 0;
     QAction *clearIndividualFormatAction = 0;
     QAction *showUnprintableUnicode = 0;
+    QAction *showUnprintableEscape = 0;
     QAction *showUnprintableOctal = 0;
     QAction *showUnprintableHexadecimal = 0;
     formatMenu.setTitle(tr("Change Display Format..."));
@@ -652,6 +653,10 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
         formatMenu.addAction(tr("Treat All Characters as Printable"));
     showUnprintableUnicode->setCheckable(true);
     showUnprintableUnicode->setChecked(unprintableBase == 0);
+    showUnprintableEscape =
+        formatMenu.addAction(tr("Show Unprintable Characters as Escape Sequences"));
+    showUnprintableEscape->setCheckable(true);
+    showUnprintableEscape->setChecked(unprintableBase == -1);
     showUnprintableOctal =
         formatMenu.addAction(tr("Show Unprintable Characters as Octal"));
     showUnprintableOctal->setCheckable(true);
@@ -932,6 +937,8 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
         debuggerCore()->openTextEditor(tr("Locals & Watchers"), contents);
     } else if (act == showUnprintableUnicode) {
         handler->setUnprintableBase(0);
+    } else if (act == showUnprintableEscape) {
+        handler->setUnprintableBase(-1);
     } else if (act == showUnprintableOctal) {
         handler->setUnprintableBase(8);
     } else if (act == showUnprintableHexadecimal) {
index 7281755..27bbf4a 100644 (file)
@@ -1640,6 +1640,11 @@ void xxxx()
 
 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 ";
     str += " big, ";
     str += "\t";