Tries to find the regex, consumes it (pos right after it) and gives the prelude (right before it) and the groups to the callback.
| 172 | |
| 173 | // Tries to find the regex, consumes it (pos right after it) and gives the prelude (right before it) and the groups to the callback. |
| 174 | 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) { |
| 175 | auto m = regex.search(input_, from == std::string::npos ? pos_ : from); |
| 176 | if (m.type == COMMON_REGEX_MATCH_TYPE_NONE) { |
| 177 | return std::nullopt; |
| 178 | } |
| 179 | auto prelude = input_.substr(pos_, m.groups[0].begin - pos_); |
| 180 | pos_ = m.groups[0].end; |
| 181 | |
| 182 | if (add_prelude_to_content) { |
| 183 | add_content(prelude); |
| 184 | } |
| 185 | if (m.type == COMMON_REGEX_MATCH_TYPE_PARTIAL) { |
| 186 | if (is_partial()) { |
| 187 | throw common_chat_msg_partial_exception(regex.str()); |
| 188 | } |
| 189 | return std::nullopt; |
| 190 | } |
| 191 | return find_regex_result{prelude, m.groups}; |
| 192 | } |
| 193 | |
| 194 | common_chat_msg_parser::find_regex_result common_chat_msg_parser::consume_regex(const common_regex & regex) { |
| 195 | if (auto result = try_consume_regex(regex)) { |
no test coverage detected