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

Function encode_name

src/json2pb/encode_decode.cpp:45–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45bool encode_name(const std::string& content, std::string& encoded_content) {
46 int index = 0;
47 size_t begin = 0;
48 bool convert = false;
49 for (std::string::const_iterator it = content.begin(); it != content.end(); ++it, ++index) {
50 if ((!isalnum(*it) &&
51 (*it != '_')) ||
52 (it == content.begin() &&
53 isdigit(*it))) {
54 if (!convert) {
55 encoded_content.clear();
56 encoded_content.reserve(2*content.size());
57 convert = true;
58 }
59 encoded_content.append(content, begin, index - begin);
60 begin = index + 1;
61
62 char pattern[6];
63 pattern[0] = '_';
64 pattern[1] = 'Z';
65 int first = *it / 100;
66 int second = (*it - first * 100) / 10;
67 int third = *it - first * 100 - second * 10;
68 pattern[2] = first + '0';
69 pattern[3] = second + '0';
70 pattern[4] = third + '0';
71 pattern[5] = '_';
72 encoded_content.append(pattern, sizeof(pattern));
73 }
74 }
75 if (!convert) {
76 return false;
77 } else {
78 encoded_content.append(content, begin, index - begin);
79 return true;
80 }
81}
82
83bool decode_name(const std::string& content, std::string& decoded_content) {
84 const int pattern_length = 6;

Callers 1

TEST_FFunction · 0.85

Calls 6

beginMethod · 0.45
endMethod · 0.45
clearMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45

Tested by 1

TEST_FFunction · 0.68