MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / gbnf_escape_char_class

Function gbnf_escape_char_class

common/peg-parser.cpp:1460–1508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1458}
1459
1460static std::string gbnf_escape_char_class(uint32_t c) {
1461 if (c == '-' || c == ']' || c == '[' || c == '\\') {
1462 return "\\" + std::string(1, (char) c);
1463 }
1464 // Escape whitespace control characters
1465 if (c == '\n') {
1466 return "\\n";
1467 }
1468 if (c == '\t') {
1469 return "\\t";
1470 }
1471 if (c == '\r') {
1472 return "\\r";
1473 }
1474
1475 // Printable ASCII
1476 if (c >= 0x20 && c <= 0x7E) {
1477 return std::string(1, (char) c);
1478 }
1479
1480 // Hex escape
1481 char buf[16];
1482 const char * hex = "0123456789ABCDEF";
1483
1484 if (c <= 0xFF) {
1485 buf[0] = '\\';
1486 buf[1] = 'x';
1487 buf[2] = hex[(c >> 4) & 0xF];
1488 buf[3] = hex[c & 0xF];
1489 buf[4] = '\0';
1490 } else if (c <= 0xFFFF) {
1491 buf[0] = '\\';
1492 buf[1] = 'u';
1493 buf[2] = hex[(c >> 12) & 0xF];
1494 buf[3] = hex[(c >> 8) & 0xF];
1495 buf[4] = hex[(c >> 4) & 0xF];
1496 buf[5] = hex[c & 0xF];
1497 buf[6] = '\0';
1498 } else {
1499 buf[0] = '\\';
1500 buf[1] = 'U';
1501 for (int i = 0; i < 8; i++) {
1502 buf[2 + i] = hex[(c >> ((7 - i) * 4)) & 0xF];
1503 }
1504 buf[10] = '\0';
1505 }
1506
1507 return std::string(buf);
1508}
1509
1510static std::string gbnf_excluding_pattern(const std::vector<std::string> & strings) {
1511 trie matcher(strings);

Callers 1

gbnf_excluding_patternFunction · 0.85

Calls 1

stringClass · 0.85

Tested by

no test coverage detected