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

Function parse_char

smallthinker/src/llama-grammar.cpp:159–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159static std::pair<uint32_t, const char *> parse_char(const char * src) {
160 if (*src == '\\') {
161 switch (src[1]) {
162 case 'x': return parse_hex(src + 2, 2);
163 case 'u': return parse_hex(src + 2, 4);
164 case 'U': return parse_hex(src + 2, 8);
165 case 't': return std::make_pair('\t', src + 2);
166 case 'r': return std::make_pair('\r', src + 2);
167 case 'n': return std::make_pair('\n', src + 2);
168 case '\\':
169 case '"':
170 case '[':
171 case ']':
172 return std::make_pair(src[1], src + 2);
173 default:
174 throw std::runtime_error(std::string("unknown escape at ") + src);
175 }
176 } else if (*src) {
177 return decode_utf8(src);
178 }
179 throw std::runtime_error("unexpected end of input");
180}
181
182static void print_grammar_char(FILE * file, uint32_t c) {
183 if (0x20 <= c && c <= 0x7f) {

Callers 1

parse_sequenceMethod · 0.70

Calls 3

parse_hexFunction · 0.70
decode_utf8Function · 0.70
stringClass · 0.50

Tested by

no test coverage detected