223 const thread_local QRegularExpression rx(
"([-+]?\\d*\\.?\\d+\\s+\\S+)", QRegularExpression::CaseInsensitiveOption );
224 const thread_local QRegularExpression rxtime(
".* \\d{1,2}(:)\\d{1,2}(:)\\d{1,2}.*", QRegularExpression::CaseInsensitiveOption );
226 const QRegularExpressionMatch matchtime = rxtime.match(
string );
227 QString modedString = QString(
string );
228 if ( matchtime.hasMatch() )
231 modedString.replace( matchtime.capturedStart( 2 ), 1,
" minutes " );
233 modedString.replace( matchtime.capturedStart( 1 ), 1,
" hours " );
234 modedString.append(
" seconds" );
239 QRegularExpressionMatch match = rx.match( modedString );
240 while ( match.hasMatch() )
242 list << match.captured( 1 );
243 pos = match.capturedStart() + match.capturedLength();
244 match = rx.match( modedString, pos );
247 const thread_local QMap<int, QStringList> map{{
248 {1, QStringList() << QStringLiteral(
"second" ) << QStringLiteral(
"seconds" ) << QObject::tr(
"second|seconds",
"list of words separated by | which reference years" ).split(
'|' )},
249 { 0 +
MINUTE, QStringList() << QStringLiteral(
"minute" ) << QStringLiteral(
"minutes" ) << QObject::tr(
"minute|minutes",
"list of words separated by | which reference minutes" ).split(
'|' ) },
250 {0 +
HOUR, QStringList() << QStringLiteral(
"hour" ) << QStringLiteral(
"hours" ) << QObject::tr(
"hour|hours",
"list of words separated by | which reference minutes hours" ).split(
'|' )},
251 {0 +
DAY, QStringList() << QStringLiteral(
"day" ) << QStringLiteral(
"days" ) << QObject::tr(
"day|days",
"list of words separated by | which reference days" ).split(
'|' )},
252 {0 +
WEEKS, QStringList() << QStringLiteral(
"week" ) << QStringLiteral(
"weeks" ) << QObject::tr(
"week|weeks",
"wordlist separated by | which reference weeks" ).split(
'|' )},
253 {0 +
MONTHS, QStringList() << QStringLiteral(
"month" ) << QStringLiteral(
"months" ) << QStringLiteral(
"mon" ) << QObject::tr(
"month|months|mon",
"list of words separated by | which reference months" ).split(
'|' )},
254 {0 +
YEARS, QStringList() << QStringLiteral(
"year" ) << QStringLiteral(
"years" ) << QObject::tr(
"year|years",
"list of words separated by | which reference years" ).split(
'|' )},
257 const thread_local QRegularExpression splitRx(
"\\s+" );
259 for (
const QString &match : std::as_const( list ) )
261 const QStringList split = match.split( splitRx );
263 const double value = split.at( 0 ).toDouble( &ok );
269 bool matched =
false;
270 QMap<int, QStringList>::const_iterator it = map.constBegin();
271 for ( ; it != map.constEnd(); ++it )
273 const int duration = it.key();
274 const QStringList durationIdentifiers = it.value();
275 for (
const QString &identifier : durationIdentifiers )
277 if ( match.contains( identifier, Qt::CaseInsensitive ) )