changeset 56:5410f9f279ea

Redefine question pattern to be more robust We now assume that a question begins after two empty lines.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 09 Aug 2016 09:59:16 +0200
parents aaaf8cdbc85c
children e66918e24edd
files src/constants.h src/converter.cpp src/l10n/main_de_DE.ts
diffstat 3 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/constants.h	Wed Jul 20 16:57:52 2016 +0200
+++ b/src/constants.h	Tue Aug 09 09:59:16 2016 +0200
@@ -55,7 +55,9 @@
  * A new question is the first unquoted string after the position
  * that is followed after a newline by the word "Answer"
  */
-#define QUESTION_PATTERN "([^\"]+)^(Answer.*$)", QRegularExpression::MultilineOption
+#define QUESTION_PATTERN "\n\n(.*)\n+(Answer.*$)", QRegularExpression::MultilineOption
+
+#define FIRST_QUESTION_PATTERN "(.*)\n+(Answer.*$)", QRegularExpression::MultilineOption
 
 /**
  * @brief Identifiying line that shows a question is a choice question. */
@@ -71,7 +73,7 @@
 
 /**
  * @brief The pattern used to match a free text answer. */
-#define FREETXT_PATTERN "\"([^\"]*)\"", QRegularExpression::MultilineOption
+#define FREETXT_PATTERN "\"([^\"]*)\"?", QRegularExpression::MultilineOption
 
 #define TITLE_ROW_HEIGHT 30
 
--- a/src/converter.cpp	Wed Jul 20 16:57:52 2016 +0200
+++ b/src/converter.cpp	Tue Aug 09 09:59:16 2016 +0200
@@ -180,12 +180,13 @@
     QRegularExpression choiceEx(CHOICE_PATTERN);
     QRegularExpression choiceAltEx(CHOICE_UNFILLED_PATTERN);
     QRegularExpression freetxtEx(FREETXT_PATTERN);
+    QRegularExpression firstQuestionEx(FIRST_QUESTION_PATTERN);
 
     input.replace("\r\n", "\n");
     input.replace("\n\r", "\n");
     input.replace("#NAME?\n", "");
 
-    QRegularExpressionMatch match = questionEx.match(input);
+    QRegularExpressionMatch match = firstQuestionEx.match(input);
     bool foundSomething = false;
     int cursor = match.capturedEnd();
     while (match.hasMatch() && cursor != -1) {
@@ -227,7 +228,7 @@
                 html << mChoiceTextStyle.arg(choiceName.toHtmlEscaped());
                 qDebug() << "Captured for choice: " << choiceMatch.captured(0);
                 bool ok;
-                const QString percentStr = choiceMatch.captured("percent");
+                QString percentStr = choiceMatch.captured("percent");
                 double percent;
                 if (percentStr.isNull()) {
                     percent = 0;
--- a/src/l10n/main_de_DE.ts	Wed Jul 20 16:57:52 2016 +0200
+++ b/src/l10n/main_de_DE.ts	Tue Aug 09 09:59:16 2016 +0200
@@ -31,12 +31,12 @@
         <translation>Die Datei &quot;%1&quot; konnte nicht geƶffnet werden.</translation>
     </message>
     <message>
-        <location filename="../converter.cpp" line="362"/>
+        <location filename="../converter.cpp" line="363"/>
         <source>Failed to parse input document.</source>
         <translation>Fehler bei der verarbeitung des Eingabedokuments.</translation>
     </message>
     <message>
-        <location filename="../converter.cpp" line="395"/>
+        <location filename="../converter.cpp" line="396"/>
         <source>Saving the XLSX document failed.</source>
         <translation>Das erstellen des XLSX Dokuments ist fehlgeschlagen.</translation>
     </message>
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)