MCPcopy Create free account
hub / github.com/catboost/catboost / ParseHex

Function ParseHex

library/cpp/http/io/chunk.cpp:9–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include <util/generic/yexception.h>
8
9static inline size_t ParseHex(const TString& s) {
10 if (s.empty()) {
11 ythrow yexception() << "can not parse chunk length(empty string)";
12 }
13
14 size_t ret = 0;
15
16 for (TString::const_iterator c = s.begin(); c != s.end(); ++c) {
17 const char ch = *c;
18
19 if (ch >= '0' && ch <= '9') {
20 ret *= 16;
21 ret += ch - '0';
22 } else if (ch >= 'a' && ch <= 'f') {
23 ret *= 16;
24 ret += 10 + ch - 'a';
25 } else if (ch >= 'A' && ch <= 'F') {
26 ret *= 16;
27 ret += 10 + ch - 'A';
28 } else if (ch == ';') {
29 break;
30 } else if (isspace(ch)) {
31 continue;
32 } else {
33 ythrow yexception() << "can not parse chunk length(" << s.data() << ")";
34 }
35 }
36
37 return ret;
38}
39
40static inline char* ToHex(size_t len, char* buf) {
41 do {

Callers 1

ProceedToNextChunkMethod · 0.70

Calls 4

emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected