Mercurial > clickerconvert
changeset 78:f230ed9022e0
Rework questions to new logic for multilne questions
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 05 Oct 2016 14:24:53 +0200 |
parents | 9412d60c8ac1 |
children | a8cd9b27e3d5 |
files | src/constants.h src/converter.cpp |
diffstat | 2 files changed, 16 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/constants.h Wed Oct 05 14:24:09 2016 +0200 +++ b/src/constants.h Wed Oct 05 14:24:53 2016 +0200 @@ -55,9 +55,7 @@ * A new question is the first unquoted string after the position * that is followed after a newline by the word "Answer" */ -#define QUESTION_PATTERN "\n\n(.*)\n+(Answer.*$)", QRegularExpression::MultilineOption - -#define FIRST_QUESTION_PATTERN "(.*)\n+(Answer.*$)", QRegularExpression::MultilineOption +#define QUESTION_PATTERN "(Answer.*)" /** * @brief Identifiying line that shows a question is a choice question. */
--- a/src/converter.cpp Wed Oct 05 14:24:09 2016 +0200 +++ b/src/converter.cpp Wed Oct 05 14:24:53 2016 +0200 @@ -77,7 +77,7 @@ "font-size:10pt;'</td>%1</td></tr>"); mAnswerTextStyle = QStringLiteral("<tr><td colspan='3' style='font-weight: bold;vertical-algin: middle;" "font-size:11pt;'>Answer<hr/></td></tr>"); - mFreeTextStyle = QStringLiteral("<tr><td colspan='3'; font-size:11pt;'>%1<hr/></td></tr>"); + mFreeTextStyle = QStringLiteral("<tr><td colspan='3'; style='font-size:11pt;'>%1<hr/></td></tr>"); mEmptyRow = QStringLiteral("<tr style='height: %1px'/>").arg(CHOICE_ROW_HEIGHT); } @@ -263,11 +263,10 @@ QRegularExpression choiceEx(CHOICE_PATTERN); QRegularExpression choiceAltEx(CHOICE_UNFILLED_PATTERN); QRegularExpression freetxtEx(FREETXT_PATTERN); - QRegularExpression firstQuestionEx(FIRST_QUESTION_PATTERN); mErrors += sanitizeInput(input); - QRegularExpressionMatch match = firstQuestionEx.match(input); + QRegularExpressionMatch match = questionEx.match(input); bool foundSomething = false; int cursor = match.capturedEnd(); while (match.hasMatch() && cursor != -1) { @@ -279,14 +278,19 @@ return; } foundSomething = true; - /* For some reason the regular expression used is not - * greedy enough if there are multiple question lines - * before the first Answer. */ - QString question = input.left(match.capturedStart() + - match.captured(1).size()); - unescapeString(question); - qDebug() << "First question: " << question; - const QString answerLine = match.captured(2).trimmed(); + /* A question is everything until the last two newlines + * before an answer line.*/ + QString question; + + int lastBreaks = input.lastIndexOf(QStringLiteral("\n\n"), cursor); + if (lastBreaks == -1) { + /* First question */ + lastBreaks = 0; + } + + question = input.mid(lastBreaks, match.capturedStart() - lastBreaks); + qDebug() << "Found question: " << question; + const QString answerLine = match.captured(1).trimmed(); xlsx.write(row, 2, QString(" "), mQuestionFmt); xlsx.write(row, 3, QString(" "), mQuestionFmt); xlsEscape(question);