MCPcopy Create free account
hub / github.com/baidu/tera / ParseDebugString

Function ParseDebugString

src/utils/string_util.cc:71–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71bool ParseDebugString(const std::string& src, std::string* dst) {
72 size_t src_len = src.size();
73 std::string tmp;
74 tmp.resize(src_len);
75
76 int state = 0; // 0: normal, 1: \, 2: \x, 3: \x[0-9a-fAZ-F]
77 char bin_char = 0;
78 size_t j = 0;
79 for (size_t i = 0; i < src_len; i++) {
80 uint8_t c = src[i];
81 if (!IsVisible(c) && !isspace(c)) {
82 return false;
83 }
84 switch (state) {
85 case 0:
86 if (c == '\\') {
87 state = 1;
88 } else {
89 tmp[j++] = c;
90 }
91 break;
92 case 1:
93 if (c == 'x') {
94 state = 2;
95 } else if (c == '\\') {
96 tmp[j++] = '\\';
97 state = 0;
98 } else {
99 return false;
100 }
101 break;
102 case 2:
103 if (!IsHex(c)) {
104 return false;
105 } else {
106 bin_char |= (ToBinary(c) << 4);
107 state = 3;
108 }
109 break;
110 case 3:
111 if (!IsHex(c)) {
112 return false;
113 } else {
114 bin_char |= ToBinary(c) & 0xF;
115 tmp[j++] = bin_char;
116 bin_char = 0;
117 state = 0;
118 }
119 break;
120 default:
121 abort();
122 break;
123 }
124 }
125
126 if (state != 0) {
127 return false;
128 }

Callers 11

ScanAndDumpDataFunction · 0.85
StartScanFunction · 0.85
BatchPutOpFunction · 0.85
BatchPutInt64OpFunction · 0.85
BatchGetOpFunction · 0.85
BatchGetInt64OpFunction · 0.85
ParseCommandFunction · 0.85
ParseCommandFunction · 0.85
ParseCommandFunction · 0.85
CheckAndParseDebugStringFunction · 0.85
ParseDelimiterFileFunction · 0.85

Calls 4

IsVisibleFunction · 0.85
IsHexFunction · 0.85
ToBinaryFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected