Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality of life enhancments #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions QGumboParser/qgumbodocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ QGumboDocument QGumboDocument::parse(QByteArray data)
return QGumboDocument(data);
}

QGumboDocument::QGumboDocument(QByteArray arr) :
options_(&kGumboDefaultOptions),
QGumboDocument QGumboDocument::parse(QByteArray data, const GumboOptions& opt)
{
return QGumboDocument(data, opt);
}

QGumboDocument::QGumboDocument(QByteArray arr, const GumboOptions& opt) :
options_(&opt),
sourceData_(arr)
{
gumboOutput_ = gumbo_parse_with_options(options_,
Expand Down
3 changes: 2 additions & 1 deletion QGumboParser/qgumbodocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class QGumboDocument
static QGumboDocument parse(const QString& htmlText);
static QGumboDocument parse(const char* utf8data);
static QGumboDocument parse(QByteArray utf8data);
static QGumboDocument parse(QByteArray utf8data, const GumboOptions& opt);

public:
~QGumboDocument();
Expand All @@ -21,7 +22,7 @@ class QGumboDocument
QGumboNode rootNode() const;

private:
QGumboDocument(QByteArray);
QGumboDocument(QByteArray, const GumboOptions& opt=kGumboDefaultOptions);

QGumboDocument(const QGumboDocument&) = delete;
QGumboDocument& operator=(const QGumboDocument&) = delete;
Expand Down
13 changes: 12 additions & 1 deletion QGumboParser/qgumbonode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ QGumboNodes QGumboNode::getElementsByClassName(const QString& name) const
const QVector<QStringRef> parts =
value.splitRef(QChar(' '), Qt::SkipEmptyParts, Qt::CaseInsensitive);
#endif

for (const QStringRef& part: parts) {
if (part.compare(name, Qt::CaseInsensitive) == 0) {
nodes.emplace_back(QGumboNode(node));
Expand Down Expand Up @@ -335,6 +334,18 @@ void QGumboNode::forEach(std::function<void(const QGumboNode&)> func) const
iterateTree(ptr_, functor);
}

void QGumboNode::forEachChild(std::function<void(const QGumboNode&)> func) const
{
Q_ASSERT(ptr_);

auto functor = [&func](GumboNode* node) {
func(QGumboNode(node));
return false;
};

iterateChildren(ptr_, functor);
}

QGumboNode::operator bool() const
{
return ptr_;
Expand Down
1 change: 1 addition & 0 deletions QGumboParser/qgumbonode.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class QGumboNode
QGumboAttributes allAttributes() const;

void forEach(std::function<void(const QGumboNode&)>) const;
void forEachChild(std::function<void(const QGumboNode&)>) const;

explicit operator bool() const;

Expand Down