Commit 498022a6 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Extract code for porting to qregularexpression

parent f94e6ab4
......@@ -37,3 +37,4 @@ add_templateparser_unittest(templateparseremailaddressrequesterlineedittest.cpp)
add_templateparser_unittest(templateparseremailaddressrequesterinterfacewidgettest.cpp)
add_templateparser_unittest(templatesinsertcommandactiontest.cpp)
add_templateparser_unittest(templatesinsertcommandpushbuttontest.cpp)
add_templateparser_unittest(templateparserutiltest.cpp)
/*
Copyright (c) 2019 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "templateparserutiltest.h"
#include "templatesutil_p.h"
#include <QTest>
QTEST_GUILESS_MAIN(TemplateParserUtilTest)
TemplateParserUtilTest::TemplateParserUtilTest(QObject *parent)
: QObject(parent)
{
}
void TemplateParserUtilTest::shouldHaveDefaultValues()
{
//TODO
}
/*
Copyright (c) 2019 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef TEMPLATEPARSERUTILTEST_H
#define TEMPLATEPARSERUTILTEST_H
#include <QObject>
class TemplateParserUtilTest : public QObject
{
Q_OBJECT
public:
explicit TemplateParserUtilTest(QObject *parent = nullptr);
~TemplateParserUtilTest() = default;
private Q_SLOTS:
void shouldHaveDefaultValues();
};
#endif // TEMPLATEPARSERUTILTEST_H
......@@ -25,6 +25,7 @@
#include "templatesconfiguration_kfg.h"
#include "templatesconfiguration.h"
#include "templatesutil.h"
#include "templatesutil_p.h"
#include <MessageCore/ImageCollector>
#include <MessageCore/StringUtil>
......@@ -1477,13 +1478,7 @@ QString TemplateParserJob::htmlMessageText(bool aStripSignature, AllowSelection
QString TemplateParserJob::quotedPlainText(const QString &selection) const
{
QString content = selection;
// Remove blank lines at the beginning:
const int firstNonWS = content.indexOf(QRegExp(QLatin1String("\\S")));
const int lineStart = content.lastIndexOf(QLatin1Char('\n'), firstNonWS);
if (lineStart >= 0) {
content.remove(0, lineStart);
}
QString content = TemplateParser::Util::removeSpaceAtBegin(selection);
const QString indentStr
= MessageCore::StringUtil::formatQuotePrefix(d->mQuoteString, d->mOrigMsg->from()->displayString());
......
......@@ -204,3 +204,16 @@ QString TemplateParser::Util::getLastNameFromEmail(const QString &str)
}
return res;
}
QString TemplateParser::Util::removeSpaceAtBegin(const QString &selection)
{
QString content = selection;
// Remove blank lines at the beginning:
const int firstNonWS = content.indexOf(QRegExp(QLatin1String("\\S")));
const int lineStart = content.lastIndexOf(QLatin1Char('\n'), firstNonWS);
if (lineStart >= 0) {
content.remove(0, lineStart);
}
return content;
}
......@@ -19,14 +19,15 @@
#ifndef TEMPLATEPARSER_TEMPLATESUTIL_P_H
#define TEMPLATEPARSER_TEMPLATESUTIL_P_H
#include "templateparser_export.h"
#include "templateparser_private_export.h"
#include <QString>
class QString;
class QStringList;
namespace TemplateParser {
namespace Util {
QStringList keywords();
QStringList keywordsWithArgs();
Q_REQUIRED_RESULT QStringList keywords();
Q_REQUIRED_RESULT QStringList keywordsWithArgs();
TEMPLATEPARSER_TESTS_EXPORT Q_REQUIRED_RESULT QString removeSpaceAtBegin(const QString &selection);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment