| 18 | } |
| 19 | |
| 20 | const std::string urlencode( const std::string& s ) |
| 21 | { |
| 22 | std::ostringstream os; |
| 23 | |
| 24 | for ( std::string::const_iterator ci = s.begin(); ci != s.end(); ++ci ) |
| 25 | { |
| 26 | if ( (*ci >= 'a' && *ci <= 'z') || |
| 27 | (*ci >= 'A' && *ci <= 'Z') || |
| 28 | (*ci >= '0' && *ci <= '9') ) |
| 29 | { // allowed |
| 30 | os << *ci; |
| 31 | } |
| 32 | else if ( *ci == ' ') |
| 33 | { |
| 34 | os << '+'; |
| 35 | } |
| 36 | else |
| 37 | { |
| 38 | os << '%' << to_hex(*ci >> 4) << to_hex(*ci % 16); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return os.str(); |
| 43 | } |
| 44 | |
| 45 | inline unsigned char from_hex ( |
| 46 | unsigned char ch |
no test coverage detected