Fix QRegularExpression

-add isValid
-add debug
This commit is contained in:
Simon De Backer
2020-09-23 21:36:48 +02:00
parent e0c8dd9585
commit b5ae1237e3
2 changed files with 22 additions and 7 deletions

View File

@@ -253,7 +253,8 @@ void ElementsLocation::setPath(const QString &path)
QRegularExpressionMatch match = re.match(tmp_path);
if (!match.hasMatch())
{
qDebug()<<"no Match => return";
qDebug()<<"no Match => return"
<<tmp_path;
return;
}
bool conv_ok;

View File

@@ -97,15 +97,29 @@ bool TitleBlockTemplateLocation::isValid() const
/**
@param loc_str String describing the location of a title block template.
*/
void TitleBlockTemplateLocation::fromString(const QString &loc_str) {
void TitleBlockTemplateLocation::fromString(const QString &loc_str)
{
collection_ = QETApp::titleBlockTemplatesCollection(QUrl(loc_str).scheme());
QRegularExpression name_from_url("^[^:]*:\\/\\/(.*)$");
if (name_from_url==QRegularExpression(loc_str)) {
name_ = name_from_url.namedCaptureGroups().at(1);
} else {
name_ = QString();
QRegularExpression name_from_url("//*(?<name>.*)");
if (!name_from_url.isValid())
{
qWarning() <<"this is an error in the code"
<< name_from_url.errorString()
<< name_from_url.patternErrorOffset();
return;
}
QRegularExpressionMatch match = name_from_url.match(loc_str);
if (!match.hasMatch())
{
qDebug()<<"no Match => return"
<<loc_str;
name_ = QString();
return;
}
name_ = match.captured("name");
}
/**