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

Method try_find_literal

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

Source from the content-addressed store, hash-verified

98}
99
100std::optional<common_chat_msg_parser::find_regex_result> common_chat_msg_parser::try_find_literal(const std::string & literal) {
101 auto idx = input_.find(literal, pos_);
102 if (idx != std::string::npos) {
103 find_regex_result res;
104 res.prelude = input_.substr(pos_, idx - pos_);
105 auto end = idx + literal.size();
106 res.groups.emplace_back(common_string_range{idx, end});
107 move_to(end);
108 return res;
109 }
110 if (is_partial_) {
111 idx = string_find_partial_stop(input_, literal);
112 if (idx != std::string::npos && idx >= pos_) {
113 find_regex_result res;
114 res.prelude = input_.substr(pos_, idx - pos_);
115 auto end = input_.size();
116 res.groups.emplace_back(common_string_range{idx, end});
117 move_to(end);
118 return res;
119 }
120 }
121 return std::nullopt;
122}
123
124void common_chat_msg_parser::consume_literal(const std::string & literal) {
125 if (!try_consume_literal(literal)) {

Callers

nothing calls this directly

Calls 4

string_find_partial_stopFunction · 0.85
findMethod · 0.80
substrMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected