Tries to find the regex, consumes it (pos right after it) and gives the prelude (right before it) and the groups to the callback.
| 438 | |
| 439 | // Tries to find the regex, consumes it (pos right after it) and gives the prelude (right before it) and the groups to the callback. |
| 440 | std::optional<common_chat_msg_parser::find_regex_result> common_chat_msg_parser::try_find_regex(const common_regex & regex, size_t from, bool add_prelude_to_content) { |
| 441 | auto m = regex.search(input_, from == std::string::npos ? pos_ : from); |
| 442 | if (m.type == COMMON_REGEX_MATCH_TYPE_NONE) { |
| 443 | return std::nullopt; |
| 444 | } |
| 445 | auto prelude = input_.substr(pos_, m.groups[0].begin - pos_); |
| 446 | pos_ = m.groups[0].end; |
| 447 | |
| 448 | if (add_prelude_to_content) { |
| 449 | add_content(prelude); |
| 450 | } |
| 451 | if (m.type == COMMON_REGEX_MATCH_TYPE_PARTIAL) { |
| 452 | if (is_partial()) { |
| 453 | throw common_chat_msg_partial_exception(regex.str()); |
| 454 | } |
| 455 | return std::nullopt; |
| 456 | } |
| 457 | return find_regex_result{prelude, m.groups}; |
| 458 | } |
| 459 | |
| 460 | common_chat_msg_parser::find_regex_result common_chat_msg_parser::consume_regex(const common_regex & regex) { |
| 461 | if (auto result = try_consume_regex(regex)) { |