MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / try_consume_regex

Method try_consume_regex

subprojects/llama.cpp/common/chat-parser.cpp:467–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

465}
466
467std::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
490std::optional<common_json> common_chat_msg_parser::try_consume_json() {
491 auto it = input_.cbegin() + pos_;

Callers 5

test_regexFunction · 0.80
parse_json_tool_callsFunction · 0.80
common_chat_parse_lfm2Function · 0.80

Calls 3

searchMethod · 0.45
strMethod · 0.45

Tested by 1

test_regexFunction · 0.64