Fix QRegularExpression

-add isValid
-add debug
This commit is contained in:
Simon De Backer
2020-09-23 22:50:41 +02:00
parent 2fe53ba6e8
commit d9f38f8a5d
3 changed files with 40 additions and 13 deletions

View File

@@ -2102,13 +2102,27 @@ template <class T> void QETApp::addWindowsListToMenu(
or -1 if none could be found.
*/
int QETApp::projectIdFromString(const QString &url) {
QRegularExpression embedded("^project([0-9]+)\\+embed.*$", QRegularExpression::CaseInsensitiveOption);
if (embedded==QRegularExpression(url)) {
bool conv_ok = false;
int project_id = embedded.namedCaptureGroups().at(1).toInt(&conv_ok);
if (conv_ok) {
return(project_id);
}
QRegularExpression embedded(
"^project(?<project_id>[0-9]+)\\+embed.*$",
QRegularExpression::CaseInsensitiveOption);
if (!embedded.isValid())
{
qWarning() <<"this is an error in the code"
<< embedded.errorString()
<< embedded.patternErrorOffset();
return(-1);
}
QRegularExpressionMatch match = embedded.match(url);
if (!match.hasMatch())
{
qDebug()<<"no Match => return"
<<url;
return(-1);
}
bool conv_ok = false;
int project_id = match.captured("project_id").toUInt(&conv_ok);
if (conv_ok) {
return(project_id);
}
return(-1);
}