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

Method Decode

encoding/percent.cpp:169–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169bool PercentEncoding::Decode(std::string *str)
170{
171 std::string& s = *str;
172 size_t write_pos = 0;
173 for (size_t i = 0; i < s.size(); ++i) {
174 uint8_t ch = 0;
175 if (s[i] == '%') {
176 if (i + 2 > s.size()) {
177 // 后面的数据不完整了,返回吧
178 return false;
179 }
180
181 if (!Ascii::IsHexDigit(s[i+1]) || !Ascii::IsHexDigit(s[i+2]))
182 return false;
183
184 ch = (HexValue(s[i+1]) << 4);
185 ch |= HexValue(s[i+2]);
186 i += 2;
187 } else if (s[i] == '+') {
188 ch = ' ';
189 } else {
190 ch = s[i];
191 }
192 s[write_pos++] = static_cast<char>(ch);
193 }
194 s.resize(write_pos);
195 return true;
196}
197
198} // namespace toft
199

Callers

nothing calls this directly

Calls 3

HexValueFunction · 0.85
resizeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected