MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / URLEncode

Method URLEncode

common/FileSystem.cpp:866–891  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

864
865
866std::string Path::URLEncode(std::string_view str)
867{
868 std::string ret;
869 ret.reserve(str.length() + ((str.length() + 3) / 4) * 3);
870
871 for (size_t i = 0, l = str.size(); i < l; i++)
872 {
873 const char c = str[i];
874 if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '-' || c == '_' ||
875 c == '.' || c == '!' || c == '~' || c == '*' || c == '\'' || c == '(' || c == ')')
876 {
877 ret.push_back(c);
878 }
879 else
880 {
881 ret.push_back('%');
882
883 const unsigned char n1 = static_cast<unsigned char>(c) >> 4;
884 const unsigned char n2 = static_cast<unsigned char>(c) & 0x0F;
885 ret.push_back((n1 >= 10) ? ('a' + (n1 - 10)) : ('0' + n1));
886 ret.push_back((n2 >= 10) ? ('a' + (n2 - 10)) : ('0' + n2));
887 }
888 }
889
890 return ret;
891}
892
893std::string Path::URLDecode(std::string_view str)
894{

Callers

nothing calls this directly

Calls 4

reserveMethod · 0.45
lengthMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected