author | Michael Krelin <hacker@klever.net> | 2005-03-31 22:06:45 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-03-31 22:06:45 (UTC) |
commit | 0942697ed6ee058809db963f9cc3126f93139de2 (patch) (side-by-side diff) | |
tree | 2a5cdf5d200e302a6d6394e4a0193929dcb11bb0 /src/util.cc | |
parent | 5b50415afdb7b708874293ac7047b9b70de78e59 (diff) | |
download | kingate-0942697ed6ee058809db963f9cc3126f93139de2.zip kingate-0942697ed6ee058809db963f9cc3126f93139de2.tar.gz kingate-0942697ed6ee058809db963f9cc3126f93139de2.tar.bz2 |
1. renamed url_escape/unescape to encode/decode
2. introduced a number of wrappers for accessing meta-variables mentioned in RFC3875
3. bumped library version info
-rw-r--r-- | src/util.cc | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/util.cc b/src/util.cc index 2e2d305..3166e62 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1,53 +1,53 @@ #include "kingate/util.h" #include "kingate/exception.h" namespace kingate { static const char *safeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789" "_-" ; - string url_escape(const string& str) { + string url_encode(const string& str) { string rv = str; string::size_type screwed = 0; for(;;) { screwed = rv.find_first_not_of(safeChars,screwed); if(screwed == string::npos) break; while(screwed<rv.length() && !strchr(safeChars,rv.at(screwed))) { char danger = rv.at(screwed); if(danger==' ') { rv.replace(screwed++,1,1,'+'); }else{ static char tmp[4] = {'%',0,0,0}; snprintf(&tmp[1],3,"%02X",0xFF&(int)danger); rv.replace(screwed,1,tmp,3); screwed+=3; } } } return rv; } - string url_unescape(const string& str) { + string url_decode(const string& str) { string rv = str; string::size_type unscrewed = 0; for(;;) { unscrewed = rv.find_first_of("%+",unscrewed); if(unscrewed == string::npos) break; if(rv.at(unscrewed)=='+') { rv.replace(unscrewed++,1,1,' '); }else{ if((rv.length()-unscrewed)<3) throw exception(CODEPOINT,"incorrectly escaped string"); // XXX: ensure it's hex? int danger = strtol(rv.substr(unscrewed+1,2).c_str(),NULL,16); rv.replace(unscrewed,3,1,danger); unscrewed++; } } return rv; } } |