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

Function PercentEncode

src/brpc/grpc.cpp:121–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121void PercentEncode(const std::string& str, std::string* str_out) {
122 std::ostringstream escaped;
123 escaped.fill('0');
124 escaped << std::hex;
125 for (std::string::const_iterator it = str.begin();
126 it != str.end(); ++it) {
127 const std::string::value_type& c = *it;
128 // Unreserved Characters are referred from
129 // https://en.wikipedia.org/wiki/Percent-encoding
130 if ((c >= 'a' && c <= 'z') ||
131 (c >= 'A' && c <= 'Z') ||
132 c == '-' || c == '_' || c == '.' || c == '~') {
133 escaped << c;
134 continue;
135 }
136 escaped << '%' << std::setw(2) << int((unsigned char) c);
137 }
138 if (str_out) {
139 *str_out = escaped.str();
140 }
141}
142
143static int hex_to_int(char c) {
144 if (c >= 'a' && c <= 'f') {

Callers 2

TEST_FFunction · 0.85
H2UnsentResponseMethod · 0.85

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by 1

TEST_FFunction · 0.68