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

Function parse_hex

subprojects/llama.cpp/src/llama-grammar.cpp:101–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101static std::pair<uint32_t, const char *> parse_hex(const char * src, int size) {
102 const char * pos = src;
103 const char * end = src + size;
104 uint32_t value = 0;
105 for ( ; pos < end && *pos; pos++) {
106 value <<= 4;
107 char c = *pos;
108 if ('a' <= c && c <= 'f') {
109 value += c - 'a' + 10;
110 } else if ('A' <= c && c <= 'F') {
111 value += c - 'A' + 10;
112 } else if ('0' <= c && c <= '9') {
113 value += c - '0';
114 } else {
115 break;
116 }
117 }
118 if (pos != end) {
119 throw std::runtime_error("expecting " + std::to_string(size) + " hex chars at " + src);
120 }
121 return std::make_pair(value, pos);
122}
123
124static const char * parse_space(const char * src, bool newline_ok) {
125 const char * pos = src;

Callers 1

parse_charFunction · 0.85

Calls 1

to_stringFunction · 0.85

Tested by

no test coverage detected