changeset 408:005633eed862

Add uniDecode, and use it when parsing logs so as to decode "\uABCD" substrings. Also force Hg encoding to utf-8.
author Chris Cannam
date Mon, 06 Jun 2011 21:20:11 +0100
parents b45e6cd9f1d4
children 69fb864a3972
files src/common.cpp src/common.h src/hgrunner.cpp src/logparser.cpp
diffstat 4 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/common.cpp	Thu May 26 15:52:11 2011 +0100
+++ b/src/common.cpp	Mon Jun 06 21:20:11 2011 +0100
@@ -257,3 +257,19 @@
 
     return s;
 }
+
+QString uniDecode(QString s)
+{
+    QString d;
+    for (int i = 0; i < s.length(); ++i) {
+        if (i+5 < s.length() && s[i] == '\\' && s[i+1] == 'u') {
+            QString uni = s.mid(i+2, 4);
+            QByteArray ba = QByteArray::fromHex(uni.toAscii());
+            d += QChar(ba[1], ba[0]);
+            i += 5;
+        } else {
+            d += s[i];
+        }
+    }
+    return d;
+}
--- a/src/common.h	Thu May 26 15:52:11 2011 +0100
+++ b/src/common.h	Mon Jun 06 21:20:11 2011 +0100
@@ -62,6 +62,8 @@
 QString getContainingRepoFolder(QString path);
 
 QString xmlEncode(QString);
+
+QString uniDecode(QString);
     
 
 #endif 	//COMMON_H
--- a/src/hgrunner.cpp	Thu May 26 15:52:11 2011 +0100
+++ b/src/hgrunner.cpp	Mon Jun 06 21:20:11 2011 +0100
@@ -286,7 +286,7 @@
 void HgRunner::dataReadyStdout()
 {
     DEBUG << "dataReadyStdout" << endl;
-	if (!m_proc) return;
+    if (!m_proc) return;
     QString chunk = QString::fromUtf8(m_proc->readAllStandardOutput());
     if (!checkPrompts(chunk)) {
         m_stdout += chunk;
@@ -296,7 +296,7 @@
 void HgRunner::dataReadyStderr()
 {
     DEBUG << "dataReadyStderr" << endl;
-	if (!m_proc) return;
+    if (!m_proc) return;
     QString chunk = QString::fromUtf8(m_proc->readAllStandardError());
     DEBUG << chunk;
     if (!checkPrompts(chunk)) {
@@ -457,6 +457,7 @@
 
     env.insert("LANG", "en_US.utf8");
     env.insert("LC_ALL", "en_US.utf8");
+    env.insert("HGENCODING", "utf8");
     env.insert("HGPLAIN", "1");
     m_proc->setProcessEnvironment(env);
 
--- a/src/logparser.cpp	Thu May 26 15:52:11 2011 +0100
+++ b/src/logparser.cpp	Mon Jun 06 21:20:11 2011 +0100
@@ -17,6 +17,7 @@
 
 #include "logparser.h"
 
+#include "common.h"
 #include "debug.h"
 
 #include <QStringList>
@@ -45,7 +46,7 @@
             if (re.indexIn(line) == 0) {
                 QString key = re.cap(1);
                 QString value = re.cap(2);
-                dictionary[key.trimmed()] = value;
+                dictionary[key.trimmed()] = uniDecode(value);
             }
         }
         results.push_back(dictionary);