MCPcopy Create free account
hub / github.com/chen3feng/toft / DecodeAppend

Method DecodeAppend

encoding/percent.cpp:137–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135///////////////////////////////////////////////////////////////////////////////
136
137bool PercentEncoding::DecodeAppend(const StringPiece& input, std::string* output)
138{
139 for (size_t i = 0; i < input.size(); ++i) {
140 uint8_t ch = 0;
141 if (input[i] == '%') {
142 if (i + 2 > input.size()) {
143 // 后面的数据不完整了,返回吧
144 return false;
145 }
146
147 if (!Ascii::IsHexDigit(input[i+1]) || !Ascii::IsHexDigit(input[i+2]))
148 return false;
149
150 ch = (HexValue(input[i+1]) << 4);
151 ch |= HexValue(input[i+2]);
152 i += 2;
153 } else if (input[i] == '+') {
154 ch = ' ';
155 } else {
156 ch = input[i];
157 }
158 *output += static_cast<char>(ch);
159 }
160 return true;
161}
162
163bool PercentEncoding::DecodeTo(const StringPiece& input, std::string* output)
164{

Callers

nothing calls this directly

Calls 2

HexValueFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected