Commit 45bd77d7 authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr

Handle year ranges written as "2019 to 2020"

parent dddd2811
......@@ -40,6 +40,7 @@ void TestCopyrightConvert::detectCopyright()
{ "Copyright (C) 2010 - 2016 by Jane Doe <my.mail(at)example.com>" , "2010-2016", "Jane Doe", "<my.mail(at)example.com>" },
{ "Copyright (C) 2020, Méven Doe <mail@example.com>", "2020", "Méven Doe", "<mail@example.com>" },
{ "Copyright (c) 2006,2007 Laurent Doe, <mail@example.com>", "2006, 2007", "Laurent Doe", "<mail@example.com>" },
{ "Copyright (C) 1997 to 2002 Jane Doe <mail@example.com>", "1997-2002", "Jane Doe", "<mail@example.com>" },
// KAppTemplate template variables
{ "Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}>" , "%{CURRENT_YEAR}", "%{AUTHOR}", "<%{EMAIL}>" },
};
......
......@@ -21,7 +21,7 @@ QRegularExpression DirectoryParser::copyrightRegExp() const
{
static auto regexp = QRegularExpression("(SPDX-FileCopyrightText:|Copyright( \\([cC]\\))|Copyright ©|©|Copyright(:)?)"
"[, ]+"
"(?<years>([0-9]+(-[0-9]+| - [0-9]+|,[ ]?[0-9]+)*|%{CURRENT_YEAR}))"
"(?<years>([0-9]+(-[0-9]+| - [0-9]+| to [0-9]+|,[ ]?[0-9]+)*|%{CURRENT_YEAR}))"
"[, ]+"
"([bB]y[ ]+)?"
"(?<name>([\u00C0-\u017Fa-zA-Z]+( [\u00C0-\u017Fa-zA-Z\\.]+)*|%{AUTHOR}))"
......@@ -38,9 +38,11 @@ QString DirectoryParser::cleanupSpaceInCopyrightYearList(const QString &original
static auto missingWhitespaceAfterCommaRegex = QRegularExpression(QStringLiteral(",(?=[0-9])"));
static auto unneededWhitespaceAroundRangeRegex = QRegularExpression(QStringLiteral(" - (?=[0-9])"));
static auto writtenRangeStatementRegex = QRegularExpression(QStringLiteral(" to (?=[0-9])"));
cleanedYearText.replace(missingWhitespaceAfterCommaRegex, QStringLiteral(", "));
cleanedYearText.replace(unneededWhitespaceAroundRangeRegex, QStringLiteral("-"));
cleanedYearText.replace(writtenRangeStatementRegex, QStringLiteral("-"));
return cleanedYearText;
}
......
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