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) (unidiff) | |
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 | |||
@@ -4,17 +4,17 @@ | |||
4 | namespace kingate { | 4 | namespace kingate { |
5 | 5 | ||
6 | static const char *safeChars = | 6 | static const char *safeChars = |
7 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 7 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
8 | "abcdefghijklmnopqrstuvwxyz" | 8 | "abcdefghijklmnopqrstuvwxyz" |
9 | "0123456789" | 9 | "0123456789" |
10 | "_-" ; | 10 | "_-" ; |
11 | 11 | ||
12 | string url_escape(const string& str) { | 12 | string url_encode(const string& str) { |
13 | string rv = str; | 13 | string rv = str; |
14 | string::size_type screwed = 0; | 14 | string::size_type screwed = 0; |
15 | for(;;) { | 15 | for(;;) { |
16 | screwed = rv.find_first_not_of(safeChars,screwed); | 16 | screwed = rv.find_first_not_of(safeChars,screwed); |
17 | if(screwed == string::npos) | 17 | if(screwed == string::npos) |
18 | break; | 18 | break; |
19 | while(screwed<rv.length() && !strchr(safeChars,rv.at(screwed))) { | 19 | while(screwed<rv.length() && !strchr(safeChars,rv.at(screwed))) { |
20 | char danger = rv.at(screwed); | 20 | char danger = rv.at(screwed); |
@@ -25,17 +25,17 @@ namespace kingate { | |||
25 | snprintf(&tmp[1],3,"%02X",0xFF&(int)danger); | 25 | snprintf(&tmp[1],3,"%02X",0xFF&(int)danger); |
26 | rv.replace(screwed,1,tmp,3); | 26 | rv.replace(screwed,1,tmp,3); |
27 | screwed+=3; | 27 | screwed+=3; |
28 | } | 28 | } |
29 | } | 29 | } |
30 | } | 30 | } |
31 | return rv; | 31 | return rv; |
32 | } | 32 | } |
33 | string url_unescape(const string& str) { | 33 | string url_decode(const string& str) { |
34 | string rv = str; | 34 | string rv = str; |
35 | string::size_type unscrewed = 0; | 35 | string::size_type unscrewed = 0; |
36 | for(;;) { | 36 | for(;;) { |
37 | unscrewed = rv.find_first_of("%+",unscrewed); | 37 | unscrewed = rv.find_first_of("%+",unscrewed); |
38 | if(unscrewed == string::npos) | 38 | if(unscrewed == string::npos) |
39 | break; | 39 | break; |
40 | if(rv.at(unscrewed)=='+') { | 40 | if(rv.at(unscrewed)=='+') { |
41 | rv.replace(unscrewed++,1,1,' '); | 41 | rv.replace(unscrewed++,1,1,' '); |