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, // 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 // 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) { if (tmpRegExp.indexIn(result) != -1) {
// cap(0) contains the whole reference // cap(0) contains the whole reference
// cap(1) contains which field is wanted // cap(1) contains which field is wanted

View file

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

View file

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