MCPcopy Create free account
hub / github.com/apache/mesos / decode

Function decode

3rdparty/libprocess/src/http.cpp:904–934  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

902
903
904Try<string> decode(const string& s)
905{
906 ostringstream out;
907
908 for (size_t i = 0; i < s.length(); ++i) {
909 if (s[i] != '%') {
910 out << (s[i] == '+' ? ' ' : s[i]);
911 continue;
912 }
913
914 // We now expect two more characters: "% HEXDIG HEXDIG"
915 if (i + 2 >= s.length() || !isxdigit(s[i+1]) || !isxdigit(s[i+2])) {
916 return Error(
917 "Malformed % escape in '" + s + "': '" + s.substr(i, 3) + "'");
918 }
919
920 // Convert from HEXDIG HEXDIG to char value.
921 istringstream in(s.substr(i + 1, 2));
922 unsigned long l;
923 in >> std::hex >> l;
924 if (l > UCHAR_MAX) {
925 ABORT("Unexpected conversion from hex string: " + s.substr(i + 1, 2) +
926 " to unsigned long: " + stringify(l));
927 }
928 out << static_cast<unsigned char>(l);
929
930 i += 2;
931 }
932
933 return out.str();
934}
935
936
937Try<vector<Response>> decodeResponses(const string& s)

Callers 2

foreachFunction · 0.70
getFunction · 0.70

Calls 3

tokenizeFunction · 0.85
ErrorClass · 0.50
stringifyClass · 0.50

Tested by

no test coverage detected