mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:28:11 +00:00
LibHTML: Use NonnullRefPtrVector in the CSS and HTML parsers.
This commit is contained in:
parent
9ab3718266
commit
e2b8a2315e
2 changed files with 6 additions and 5 deletions
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
NonnullRefPtr<StyleSheet> parse_css(const String& css)
|
NonnullRefPtr<StyleSheet> parse_css(const String& css)
|
||||||
{
|
{
|
||||||
Vector<NonnullRefPtr<StyleRule>> rules;
|
NonnullRefPtrVector<StyleRule> rules;
|
||||||
|
|
||||||
enum class State {
|
enum class State {
|
||||||
Free,
|
Free,
|
||||||
|
@ -16,7 +16,7 @@ NonnullRefPtr<StyleSheet> parse_css(const String& css)
|
||||||
|
|
||||||
struct CurrentRule {
|
struct CurrentRule {
|
||||||
Vector<Selector> selectors;
|
Vector<Selector> selectors;
|
||||||
Vector<NonnullRefPtr<StyleDeclaration>> declarations;
|
NonnullRefPtrVector<StyleDeclaration> declarations;
|
||||||
};
|
};
|
||||||
|
|
||||||
CurrentRule current_rule;
|
CurrentRule current_rule;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <AK/NonnullRefPtrVector.h>
|
||||||
#include <LibHTML/DOM/Element.h>
|
#include <LibHTML/DOM/Element.h>
|
||||||
#include <LibHTML/DOM/Text.h>
|
#include <LibHTML/DOM/Text.h>
|
||||||
#include <LibHTML/Parser/HTMLParser.h>
|
#include <LibHTML/Parser/HTMLParser.h>
|
||||||
|
@ -34,7 +35,7 @@ static bool is_self_closing_tag(const String& tag_name)
|
||||||
|
|
||||||
NonnullRefPtr<Document> parse_html(const String& html)
|
NonnullRefPtr<Document> parse_html(const String& html)
|
||||||
{
|
{
|
||||||
Vector<NonnullRefPtr<ParentNode>> node_stack;
|
NonnullRefPtrVector<ParentNode> node_stack;
|
||||||
|
|
||||||
auto doc = adopt(*new Document);
|
auto doc = adopt(*new Document);
|
||||||
node_stack.append(doc);
|
node_stack.append(doc);
|
||||||
|
@ -76,7 +77,7 @@ NonnullRefPtr<Document> parse_html(const String& html)
|
||||||
if (state == State::Free && !text_buffer.is_empty()) {
|
if (state == State::Free && !text_buffer.is_empty()) {
|
||||||
auto text_node = adopt(*new Text(String::copy(text_buffer)));
|
auto text_node = adopt(*new Text(String::copy(text_buffer)));
|
||||||
text_buffer.clear();
|
text_buffer.clear();
|
||||||
node_stack.last()->append_child(text_node);
|
node_stack.last().append_child(text_node);
|
||||||
}
|
}
|
||||||
state = new_state;
|
state = new_state;
|
||||||
text_buffer.clear();
|
text_buffer.clear();
|
||||||
|
@ -93,7 +94,7 @@ NonnullRefPtr<Document> parse_html(const String& html)
|
||||||
new_element->set_attributes(move(attributes));
|
new_element->set_attributes(move(attributes));
|
||||||
node_stack.append(new_element);
|
node_stack.append(new_element);
|
||||||
if (node_stack.size() != 1)
|
if (node_stack.size() != 1)
|
||||||
node_stack[node_stack.size() - 2]->append_child(new_element);
|
node_stack[node_stack.size() - 2].append_child(new_element);
|
||||||
|
|
||||||
if (is_self_closing_tag(new_element->tag_name()))
|
if (is_self_closing_tag(new_element->tag_name()))
|
||||||
close_tag();
|
close_tag();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue