Mercurial > clickerconvert
diff src/converter.cpp @ 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 | 1e6e7699f0b8 |
children | a8cd9b27e3d5 |
line wrap: on
line diff
--- 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);