reuse referenceRegExp

This commit is contained in:
thez3ro 2017-03-07 17:19:41 +01:00
parent a03e354504
commit 40851409fb
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
3 changed files with 10 additions and 3 deletions

View File

@ -690,7 +690,7 @@ QString Entry::resolvePlaceholder(const QString& str) const
// using format from http://keepass.info/help/base/fieldrefs.html at the time of writing,
// but supporting lookups of standard fields and references by UUID only
QRegExp tmpRegExp("\\{REF:([TUPAN])@I:([^}]+)\\}", Qt::CaseInsensitive, QRegExp::RegExp2);
QRegExp tmpRegExp = m_attributes->referenceRegExp();
if (tmpRegExp.indexIn(result) != -1) {
// cap(0) contains the whole reference
// cap(1) contains which field is wanted

View File

@ -28,6 +28,7 @@ const QString EntryAttributes::RememberCmdExecAttr = "_EXEC_CMD";
EntryAttributes::EntryAttributes(QObject* parent)
: QObject(parent)
, m_referenceRegExp("\\{REF:([TUPAN])@I:([^}]+)\\}", Qt::CaseInsensitive, QRegExp::RegExp2)
{
clear();
}
@ -77,13 +78,17 @@ bool EntryAttributes::isReference(const QString& key) const
}
QString data = value(key);
QRegExp referenceRegExp("\\{REF:([TUPAN])@I:([^}]+)\\}", Qt::CaseInsensitive, QRegExp::RegExp2);
if (referenceRegExp.indexIn(data) != -1) {
if (m_referenceRegExp.indexIn(data) != -1) {
return true;
}
return false;
}
QRegExp EntryAttributes::referenceRegExp() const
{
return m_referenceRegExp;
}
void EntryAttributes::set(const QString& key, const QString& value, bool protect)
{
bool emitModified = false;

View File

@ -36,6 +36,7 @@ public:
bool contains(const QString& key) const;
bool isProtected(const QString& key) const;
bool isReference(const QString& key) const;
QRegExp referenceRegExp() const;
void set(const QString& key, const QString& value, bool protect = false);
void remove(const QString& key);
void rename(const QString& oldKey, const QString& newKey);
@ -72,6 +73,7 @@ Q_SIGNALS:
private:
QMap<QString, QString> m_attributes;
QSet<QString> m_protectedAttributes;
QRegExp m_referenceRegExp;
};
#endif // KEEPASSX_ENTRYATTRIBUTES_H