author | Michael Krelin <hacker@klever.net> | 2020-10-07 22:52:19 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2020-10-07 22:52:19 (UTC) |
commit | c561689bf162fb22997bd88f4392f222f151c950 (patch) (side-by-side diff) | |
tree | ce4656e92c379f7089f4bb72a4b10d781b61211e /src/util.cc | |
parent | 3a4530372bc95d728dbddbac788f2c1f2d03a030 (diff) | |
download | kingate-c561689bf162fb22997bd88f4392f222f151c950.zip kingate-c561689bf162fb22997bd88f4392f222f151c950.tar.gz kingate-c561689bf162fb22997bd88f4392f222f151c950.tar.bz2 |
-rw-r--r-- | src/util.cc | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc index 48e486a..76e684f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1,32 +1,33 @@ +#include <cstring> #include "kingate/util.h" #include "kingate/exception.h" namespace kingate { static const char *safeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789" "_-" ; 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; } |