fork download
  1. #include <string>
  2. #include <sstream>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. string hex(unsigned int c)
  8. {
  9. ostringstream stm ;
  10. stm << '=' << hex << uppercase << c;
  11. return stm.str() ;
  12. }
  13.  
  14. string url_encode(const string& str)
  15. {
  16. static const string unreserved = "0123456789"
  17. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  18. "abcdefghijklmnopqrstuvwxyz"
  19. "-_.~" ;
  20. string result;
  21.  
  22. for (int i = 0; i < str.size(); i++) {
  23. unsigned char c = str[i];
  24.  
  25. if (unreserved.find(c) != string::npos) {
  26. result += c;
  27. cout << c << endl;
  28. } else {
  29. result += hex(c);
  30. cout << hex(c) << endl;
  31. }
  32. }
  33. return result;
  34. }
  35.  
  36. int main()
  37. {
  38. string test = "čau";
  39. string result = url_encode(test);
  40. //cout << test << '\n' << result << '\n';
  41. }
  42.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
=C4
=8D
a
u