* \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. */
| 99 | * \return A shared pointer to the newly created Node. |
| 100 | */ |
| 101 | std::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 | } |