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

Function match_string

smallthinker/tests/test-grammar-integration.cpp:35–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35static bool match_string(const std::string & input, llama_grammar * grammar) {
36 const auto cpts = unicode_cpts_from_utf8(input);
37
38 auto & stacks_cur = llama_grammar_get_stacks(grammar);
39
40 for (const auto & cpt : cpts) {
41 llama_grammar_accept(grammar, cpt);
42
43 if (stacks_cur.empty()) {
44 // no stacks means that the grammar failed to match at this point
45 return false;
46 }
47 }
48
49 for (const auto & stack : stacks_cur) {
50 if (stack.empty()) {
51 // An empty stack means that the grammar has been completed
52 return true;
53 }
54 }
55
56 return false;
57}
58
59static void test(const std::string & test_desc, const std::string & grammar_str, const std::vector<std::string> & passing_strings, const std::vector<std::string> & failing_strings) {
60 fprintf(stderr, "⚫ Testing %s\n%s\n", test_desc.c_str(), grammar_str.c_str());

Callers 1

testFunction · 0.70

Calls 3

unicode_cpts_from_utf8Function · 0.85
llama_grammar_acceptFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected