| 129 | } |
| 130 | |
| 131 | void insert(const std::string & word) { |
| 132 | size_t current = 0; |
| 133 | size_t pos = 0; |
| 134 | while (pos < word.length()) { |
| 135 | auto result = common_parse_utf8_codepoint(word, pos); |
| 136 | if (result.status != utf8_parse_result::SUCCESS) { |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | uint32_t ch = result.codepoint; |
| 141 | pos += result.bytes_consumed; |
| 142 | |
| 143 | auto it = nodes[current].children.find(ch); |
| 144 | if (it == nodes[current].children.end()) { |
| 145 | size_t child = create_node(); |
| 146 | nodes[current].children[ch] = child; |
| 147 | current = child; |
| 148 | } else { |
| 149 | current = it->second; |
| 150 | } |
| 151 | } |
| 152 | nodes[current].is_word = true; |
| 153 | } |
| 154 | }; |
| 155 | |
| 156 | static std::pair<uint32_t, size_t> parse_hex_escape(const std::string & str, size_t pos, int hex_count) { |
no test coverage detected