# HG changeset patch # User Andre Heinecke # Date 1475670293 -7200 # Node ID f230ed9022e02750dd13c762642c14d8c018a48d # Parent 9412d60c8ac15d4883951106400a6045fd0336f3 Rework questions to new logic for multilne questions diff -r 9412d60c8ac1 -r f230ed9022e0 src/constants.h --- 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. */ diff -r 9412d60c8ac1 -r f230ed9022e0 src/converter.cpp --- 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;'%1"); mAnswerTextStyle = QStringLiteral("Answer
"); - mFreeTextStyle = QStringLiteral("%1
"); + mFreeTextStyle = QStringLiteral("%1
"); mEmptyRow = QStringLiteral("").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);