MCPcopy Create free account
hub / github.com/beginner-jhj/mini_browser / create_node

Function create_node

src/html/html_parser.cpp:101–118  ·  view source on GitHub ↗

* \brief Creates a Node object from a TOKEN. * * Converts a single TOKEN into a corresponding Node. For text tokens, creates * a TEXT type node. For element tokens, creates an ELEMENT type node and * populates its attributes from the token's attribute map. * * \param token The TOKEN object to convert into a Node. * \return A shared pointer to the newly created Node. */

Source from the content-addressed store, hash-verified

99 * \return A shared pointer to the newly created Node.
100 */
101std::shared_ptr<NODE> create_node(const TOKEN &token)
102{
103 if (token.type == TOKEN_TYPE::TEXT)
104 {
105 return std::make_shared<NODE>(NODE_TYPE::TEXT, token.value);
106 }
107
108 auto node = std::make_shared<NODE>(NODE_TYPE::ELEMENT, token.value);
109
110 if (!token.attributes.empty())
111 {
112 for (auto [name, value] : token.attributes)
113 {
114 node->set_attribute(name, value);
115 }
116 }
117 return node;
118}

Callers 1

parseFunction · 0.85

Calls 1

set_attributeMethod · 0.80

Tested by

no test coverage detected