aboutsummaryrefslogtreecommitdiff
path: root/src/parser/tree_builder.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-04-11 03:28:01 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-04-11 03:28:01 +0800
commitd68d4495395cabc10407e088b6781bf7ee5035e1 (patch)
treee9633cfed14cc8f38396971e41434dfabc5034c1 /src/parser/tree_builder.cc
parent828b10cc337784444b18e4c178a75f87c771412a (diff)
downloadrwebbrowser-d68d4495395cabc10407e088b6781bf7ee5035e1.tar.gz
rwebbrowser-d68d4495395cabc10407e088b6781bf7ee5035e1.tar.xz
style: apply consistent code formatting and bracing style across the codebase
Diffstat (limited to 'src/parser/tree_builder.cc')
-rw-r--r--src/parser/tree_builder.cc87
1 files changed, 39 insertions, 48 deletions
diff --git a/src/parser/tree_builder.cc b/src/parser/tree_builder.cc
index 51a8a51..4f7f87e 100644
--- a/src/parser/tree_builder.cc
+++ b/src/parser/tree_builder.cc
@@ -24,67 +24,58 @@
namespace ricochet::parser {
namespace {
-struct TokenVisitor {
- std::vector<DomNode>* stack;
+struct TokenVisitor
+{
+ std::vector<DomNode>* stack;
- void operator()(const TextToken& token) const {
- stack->back().children.emplace_back(
- DomNode{
- .tag_name = "",
- .text_content = token.content,
- .children = {}
- }
- );
- }
+ void operator()( const TextToken& token ) const
+ {
+ stack->back().children.emplace_back(
+ DomNode { .tag_name = "", .text_content = token.content, .children = {} } );
+ }
+
+ void operator()( const TagOpenToken& token ) const
+ {
+ DomNode new_node { .tag_name = token.name, .text_content = "", .children = {} };
- void operator()(const TagOpenToken& token) const {
- DomNode new_node{
- .tag_name = token.name,
- .text_content = "",
- .children = {}
- };
+ if ( token.name == "meta" || token.name == "link" || token.name == "img" || token.name == "br"
+ || token.name == "hr" || token.name == "input" || token.name == "base" || token.name == "col" ) {
- if (token.name == "meta" || token.name == "link" || token.name == "img" ||
- token.name == "br" || token.name == "hr" || token.name == "input" ||
- token.name == "base" || token.name == "col") {
-
- stack->back().children.push_back(std::move(new_node));
- } else {
- stack->push_back(std::move(new_node));
- }
+ stack->back().children.push_back( std::move( new_node ) );
+ } else {
+ stack->push_back( std::move( new_node ) );
}
+ }
- void operator()(const TagCloseToken& /*token*/) const {
- if (stack->size() > 1) {
- DomNode completed_node = std::move(stack->back());
- stack->pop_back();
- stack->back().children.push_back(std::move(completed_node));
- }
+ void operator()( const TagCloseToken& /*token*/ ) const
+ {
+ if ( stack->size() > 1 ) {
+ DomNode completed_node = std::move( stack->back() );
+ stack->pop_back();
+ stack->back().children.push_back( std::move( completed_node ) );
}
+ }
};
} // namespace
-DomNode TreeBuilder::build(const std::vector<HtmlToken>& tokens) const // NOLINT(readability-convert-member-functions-to-static)
+DomNode TreeBuilder::build( // NOLINT(readability-convert-member-functions-to-static)
+ const std::vector<HtmlToken>& tokens ) const
{
- std::vector<DomNode> stack;
- stack.emplace_back(DomNode{
- .tag_name = "Document",
- .text_content = "",
- .children = {}
- });
+ std::vector<DomNode> stack;
+ stack.emplace_back( DomNode { .tag_name = "Document", .text_content = "", .children = {} } );
- TokenVisitor visitor{&stack};
- for (const auto& token : tokens) {
- std::visit(visitor, token);
- }
+ TokenVisitor visitor { &stack };
+ for ( const auto& token : tokens ) {
+ std::visit( visitor, token );
+ }
- while (stack.size() > 1) {
- DomNode completed_node = std::move(stack.back());
- stack.pop_back();
- stack.back().children.push_back(std::move(completed_node));
- }
+ while ( stack.size() > 1 ) {
+ DomNode completed_node = std::move( stack.back() );
+ stack.pop_back();
+ stack.back().children.push_back( std::move( completed_node ) );
+ }
- return std::move(stack.front());
+ return std::move( stack.front() );
}
} // namespace ricochet::parser \ No newline at end of file