Guest User

Untitled

a guest
Nov 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. unsigned char hs2i(char c)
  2. {
  3. if ('0' <= c && c <= '9') {
  4. return ((unsigned char)c - '0');
  5. } else if ('a' <= c && c <= 'f') {
  6. return ((unsigned char)c - 'a' + 10);
  7. } else if ('A' <= c && c <= 'F') {
  8. return ((unsigned char)c - 'A' + 10);
  9. } else {
  10. return 0;
  11. }
  12. }
  13.  
  14. String decodeUri(String s) {
  15. String a = "";
  16. char c;
  17. std::pair<char, char> h;
  18. for (int i = 0; i < s.length(); i++) {
  19. c = s.charAt(i);
  20. if (c == '+') {
  21. a += ' ';
  22. } else if (c == '%') {
  23. h.first = s.charAt(++i);
  24. h.second = s.charAt(++i);
  25. c = (hs2i(h.first) << 4) | hs2i(h.second);
  26. a += c;
  27. } else {
  28. a += c;
  29. }
  30. yield();
  31. }
  32. return a;
  33. }
Add Comment
Please, Sign In to add comment