| 199 | } |
| 200 | |
| 201 | std::optional<common_chat_msg_parser::find_regex_result> common_chat_msg_parser::try_consume_regex(const common_regex & regex) { |
| 202 | auto m = regex.search(input_, pos_); |
| 203 | if (m.type == COMMON_REGEX_MATCH_TYPE_NONE) { |
| 204 | return std::nullopt; |
| 205 | } |
| 206 | if (m.type == COMMON_REGEX_MATCH_TYPE_PARTIAL) { |
| 207 | if (is_partial()) { |
| 208 | throw common_chat_msg_partial_exception(regex.str()); |
| 209 | } |
| 210 | return std::nullopt; |
| 211 | } |
| 212 | if (m.groups[0].begin != pos_) { |
| 213 | // Didn't match at the current position. |
| 214 | return std::nullopt; |
| 215 | } |
| 216 | pos_ = m.groups[0].end; |
| 217 | |
| 218 | return find_regex_result { |
| 219 | /* .prelude = */ "", |
| 220 | m.groups, |
| 221 | }; |
| 222 | } |
| 223 | |
| 224 | std::optional<common_json> common_chat_msg_parser::try_consume_json() { |
| 225 | auto it = input_.cbegin() + pos_; |