diff src/converter.cpp @ 65:defd29b9f25a

Converter: Unescape IMG and Latex references
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 26 Aug 2016 15:26:17 +0200
parents 4d65e654abf7
children dab9c19252bd
line wrap: on
line diff
--- a/src/converter.cpp	Fri Aug 26 12:25:03 2016 +0200
+++ b/src/converter.cpp	Fri Aug 26 15:26:17 2016 +0200
@@ -136,6 +136,24 @@
     return;
 }
 
+static void unescapeRegex(QString &str, const QRegularExpression &exp)
+{
+    QRegularExpressionMatch match = exp.match(str);
+    while (match.hasMatch()) {
+        str.replace(match.capturedStart(), match.capturedLength(), match.captured(1));
+        match = exp.match(str);
+    }
+}
+
+static void unescapeString(QString &str)
+{
+    static const QRegularExpression imgEx(IMAGE_PATTERN);
+    static const QRegularExpression texEx(LATEX_PATTERN);
+
+    unescapeRegex(str, imgEx);
+    unescapeRegex(str, texEx);
+}
+
 void Converter::convertToXSLX(QTextStream& instream, QList<QFile *>outputs)
 {
     Document xlsx;
@@ -198,7 +216,8 @@
             return;
         }
         foundSomething = true;
-        const QString question = match.captured(1).trimmed();
+        QString question = match.captured(1).trimmed();
+        unescapeString(question);
         const QString answerLine = match.captured(2).trimmed();
         xlsx.write(row, 2, QString(" "), mQuestionFmt);
         xlsx.write(row, 3, QString(" "), mQuestionFmt);
@@ -224,6 +243,7 @@
                 if (choiceName.startsWith("=")) {
                     choiceName = " " + choiceName;
                 }
+                unescapeString(choiceName);
                 xlsx.write(row, 1, choiceName, mChoiceTextFmt);
                 html << mChoiceTextStyle.arg(choiceName.toHtmlEscaped());
                 qDebug() << "Captured for choice: " << choiceMatch.captured(0);
@@ -261,9 +281,10 @@
             bool additionalFound = false;
             while (choiceMatch.hasMatch() && choiceMatch.capturedStart() <= cursor + 1) {
                 additionalFound = true;
-                const QString choice = choiceMatch.captured(1);
+                QString choice = choiceMatch.captured(1);
                 cursor = choiceMatch.capturedEnd();
                 /* Alternative answer that is just a list of strings */
+                unescapeString(choice);
                 qDebug() << "Caputured unfilled choice: " << choice;
                 html << mChoiceTextStyle.arg(choice.toHtmlEscaped());
                 makeBar(html, 0, doc);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)