diff options
author | Bryan Ischo <bryan@ischo.com> | 2011-09-27 23:56:27 -0700 |
---|---|---|
committer | Bryan Ischo <bryan@ischo.com> | 2011-09-27 23:56:27 -0700 |
commit | 8c729d426be864c9ce6d053af98a8fccbf5d7122 (patch) | |
tree | e9d251a9c8a96a602eaf7c3112559932fb8fbe9b /src | |
parent | a744e14688d5085e80a0c4520baababfdbf99ada (diff) | |
download | ceph-libs3-8c729d426be864c9ce6d053af98a8fccbf5d7122.tar.gz |
Added fix and minor optimizations to urlEncode submitted years ago by
Curtis Spencer that I forgot to integrate back then.
Diffstat (limited to 'src')
-rw-r--r-- | src/util.c | 25 |
1 files changed, 9 insertions, 16 deletions
@@ -56,7 +56,6 @@ static int checkString(const char *str, const char *format) int urlEncode(char *dest, const char *src, int maxSrcSize) { - static const char *urlSafe = "-_.!~*'()/"; static const char *hex = "0123456789ABCDEF"; int len = 0; @@ -66,28 +65,22 @@ int urlEncode(char *dest, const char *src, int maxSrcSize) *dest = 0; return 0; } - const char *urlsafe = urlSafe; - int isurlsafe = 0; - while (*urlsafe) { - if (*urlsafe == *src) { - isurlsafe = 1; - break; - } - urlsafe++; - } - if (isurlsafe || isalnum(*src)) { - *dest++ = *src++; + unsigned char c = *src; + if (isalnum(c) || + (c == '-') || (c == '_') || (c == '.') || (c == '!') || + (c == '~') || (c == '*') || (c == '\'') || (c == '(') || + (c == ')') || (c == '/')) { + *dest++ = c; } else if (*src == ' ') { *dest++ = '+'; - src++; } else { *dest++ = '%'; - *dest++ = hex[*src / 16]; - *dest++ = hex[*src % 16]; - src++; + *dest++ = hex[c >> 4]; + *dest++ = hex[c & 15]; } + src++; } *dest = 0; |