Skip to content

Commit

Permalink
Added a constructor and a operator. Applied patch from stoneyrh@163.com.
Browse files Browse the repository at this point in the history
  • Loading branch information
aoym committed Dec 30, 2015
1 parent ec87e8f commit e0da48d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/thtmlattribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
web elements.
*/

/*!
Constructor.
*/
THtmlAttribute::THtmlAttribute(const QString &key, const QString &value)
{
QList<QPair<QString, QString>>::append(qMakePair(key, value));
}

/*!
Copy constructor.
*/
Expand All @@ -34,8 +42,8 @@ THtmlAttribute::THtmlAttribute(const QList<QPair<QString, QString>> &list)
*/
bool THtmlAttribute::contains(const QString &key) const
{
for (QListIterator<QPair<QString, QString>> i(*this); i.hasNext(); ) {
if (i.next().first == key)
for (const auto &p : *this) {
if (p.first == key)
return true;
}
return false;
Expand All @@ -57,6 +65,15 @@ void THtmlAttribute::append(const QString &key, const QString &value)
QList<QPair<QString, QString>>::append(qMakePair(key, value));
}

/*!
Inserts a new item at the end of the attributes.
*/
THtmlAttribute& THtmlAttribute::operator()(const QString &key, const QString &value)
{
append(key, value);
return *this;
}

/*!
Assignment operator.
*/
Expand All @@ -83,8 +100,7 @@ THtmlAttribute THtmlAttribute::operator|(const THtmlAttribute &other) const
QString THtmlAttribute::toString(bool escape) const
{
QString string;
for (QListIterator<QPair<QString, QString>> i(*this); i.hasNext(); ) {
const QPair<QString, QString> &p = i.next();
for (const auto &p : *this) {
string.append(" ").append(p.first);
if (!p.second.isNull()) {
string.append("=\"");
Expand All @@ -95,6 +111,7 @@ QString THtmlAttribute::toString(bool escape) const
return string;
}


/*!
\fn THtmlAttribute::THtmlAttribute()
Constructor.
Expand Down
2 changes: 2 additions & 0 deletions src/thtmlattribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ class T_CORE_EXPORT THtmlAttribute : public QList<QPair<QString, QString>>
{
public:
THtmlAttribute() { }
THtmlAttribute(const QString &key, const QString &value);
THtmlAttribute(const THtmlAttribute &other);
THtmlAttribute(const QList<QPair<QString, QString>> &list);

bool contains(const QString &key) const;
void prepend(const QString &key, const QString &value);
void append(const QString &key, const QString &value);
THtmlAttribute& operator()(const QString &key, const QString &value);
THtmlAttribute &operator=(const THtmlAttribute &other);
THtmlAttribute operator|(const THtmlAttribute &other) const;
QString toString(bool escape = true) const;
Expand Down

0 comments on commit e0da48d

Please sign in to comment.