Check if a delimiter starts at the given position
| 52 | |
| 53 | // Check if a delimiter starts at the given position |
| 54 | match_result check_at(std::string_view sv, size_t start_pos) const { |
| 55 | size_t current = 0; // Start at root |
| 56 | size_t pos = start_pos; |
| 57 | |
| 58 | // LOG_DBG("%s: checking at pos %zu, sv='%s'\n", __func__, start_pos, std::string(sv).c_str()); |
| 59 | |
| 60 | while (pos < sv.size()) { |
| 61 | auto result = common_parse_utf8_codepoint(sv, pos); |
| 62 | if (result.status != utf8_parse_result::SUCCESS) { |
| 63 | break; |
| 64 | } |
| 65 | |
| 66 | auto it = nodes[current].children.find(result.codepoint); |
| 67 | if (it == nodes[current].children.end()) { |
| 68 | // Can't continue matching |
| 69 | return match_result{match_result::NO_MATCH}; |
| 70 | } |
| 71 | |
| 72 | current = it->second; |
| 73 | pos += result.bytes_consumed; |
| 74 | |
| 75 | // Check if we've matched a complete word |
| 76 | if (nodes[current].is_word) { |
| 77 | return match_result{match_result::COMPLETE_MATCH}; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // Reached end of input while still in the trie (not at root) |
| 82 | if (current != 0) { |
| 83 | // We're in the middle of a potential match |
| 84 | return match_result{match_result::PARTIAL_MATCH}; |
| 85 | } |
| 86 | |
| 87 | // Reached end at root (no match) |
| 88 | return match_result{match_result::NO_MATCH}; |
| 89 | } |
| 90 | |
| 91 | struct prefix_and_next { |
| 92 | std::vector<uint32_t> prefix; |
no test coverage detected