| 465 | } |
| 466 | |
| 467 | std::optional<common_chat_msg_parser::find_regex_result> common_chat_msg_parser::try_consume_regex(const common_regex & regex) { |
| 468 | auto m = regex.search(input_, pos_); |
| 469 | if (m.type == COMMON_REGEX_MATCH_TYPE_NONE) { |
| 470 | return std::nullopt; |
| 471 | } |
| 472 | if (m.type == COMMON_REGEX_MATCH_TYPE_PARTIAL) { |
| 473 | if (is_partial()) { |
| 474 | throw common_chat_msg_partial_exception(regex.str()); |
| 475 | } |
| 476 | return std::nullopt; |
| 477 | } |
| 478 | if (m.groups[0].begin != pos_) { |
| 479 | // Didn't match at the current position. |
| 480 | return std::nullopt; |
| 481 | } |
| 482 | pos_ = m.groups[0].end; |
| 483 | |
| 484 | return find_regex_result { |
| 485 | /* .prelude = */ "", |
| 486 | m.groups, |
| 487 | }; |
| 488 | } |
| 489 | |
| 490 | std::optional<common_json> common_chat_msg_parser::try_consume_json() { |
| 491 | auto it = input_.cbegin() + pos_; |