MCPcopy Create free account
hub / github.com/Barracuda09/SATPI / getPercentDecoding

Method getPercentDecoding

src/StringConverter.cpp:318–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316}
317
318std::string StringConverter::getPercentDecoding(const std::string &msg) {
319 std::string decoded = msg;
320 // Search for ASCII Percent-Encoding and decode it
321 std::string::size_type n = 0;
322 while ((n = decoded.find("%", n)) != std::string::npos) {
323 ++n;
324 if ( n + 2 > decoded.size()) {
325 break;
326 }
327 const char c1 = decoded[n];
328 const char c2 = decoded[n + 1];
329 if (std::isdigit(c1) && (std::isdigit(c2) || std::isalpha(c2))) {
330 // It was ex. %2F -> decode it to ASCII '/'
331 const std::string sub = decoded.substr(n, 2);
332 decoded.replace(n - 1, 3, 1, static_cast<char>(std::stoi(sub, 0 , 16)));
333 } else if (c1 == '%' && std::isdigit(c2)) {
334 // It was ex. %%2F -> remove first % (so double percent decoded)
335 decoded.erase(n - 1, 1);
336 n += 2;
337 }
338 }
339 return decoded;
340}
341
342StringVector StringConverter::parseCommandArgumentString(const std::string &cmd) {
343 std::string arg;

Callers

nothing calls this directly

Calls 1

findMethod · 0.80

Tested by

no test coverage detected