MCPcopy Create free account
hub / github.com/apache/brpc / match_pattern

Function match_pattern

src/json2pb/encode_decode.cpp:24–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22namespace json2pb {
23
24inline int match_pattern(const std::string& str, int index) {
25 //pattern: _Zxxx_
26 const char digit = '0';
27 const int pattern_length = 6;
28
29 int length = str.size();
30 if (length <= index || length - index < pattern_length) {
31 return -1;
32 }
33 if (str[index] != '_' ||
34 str[index + 1] != 'Z' ||
35 str[index + 5] != '_' ||
36 !isdigit(str[index + 2]) ||
37 !isdigit(str[index + 3]) ||
38 !isdigit(str[index + 4])) {
39 return -1;
40 }
41 int sum = (str[index + 2] - digit) * 100 + (str[index + 3] - digit) * 10 + (str[index + 4] - digit);
42 return sum < 256 ? sum : -1;
43}
44
45bool encode_name(const std::string& content, std::string& encoded_content) {
46 int index = 0;

Callers 1

decode_nameFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected