MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / try_consume_regex

Method try_consume_regex

smallthinker/common/chat-parser.cpp:201–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201std::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
224std::optional<common_json> common_chat_msg_parser::try_consume_json() {
225 auto it = input_.cbegin() + pos_;

Callers 3

test_regexFunction · 0.80
parse_json_tool_callsFunction · 0.80

Calls 3

searchMethod · 0.45
strMethod · 0.45

Tested by 1

test_regexFunction · 0.64