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

Function parse_hex

common/grammar-parser.cpp:53–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51 }
52
53 static std::pair<uint32_t, const char *> parse_hex(const char * src, int size) {
54 const char * pos = src;
55 const char * end = src + size;
56 uint32_t value = 0;
57 for ( ; pos < end && *pos; pos++) {
58 value <<= 4;
59 char c = *pos;
60 if ('a' <= c && c <= 'f') {
61 value += c - 'a' + 10;
62 } else if ('A' <= c && c <= 'F') {
63 value += c - 'A' + 10;
64 } else if ('0' <= c && c <= '9') {
65 value += c - '0';
66 } else {
67 break;
68 }
69 }
70 if (pos != end) {
71 throw std::runtime_error("expecting " + std::to_string(size) + " hex chars at " + src);
72 }
73 return std::make_pair(value, pos);
74 }
75
76 static const char * parse_space(const char * src, bool newline_ok) {
77 const char * pos = src;

Callers 1

parse_charFunction · 0.70

Calls 1

to_stringFunction · 0.50

Tested by

no test coverage detected