summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>2003-04-28 16:18:34 +0000
committerSascha Schumann <sas@php.net>2003-04-28 16:18:34 +0000
commitf00753614789a37f18bdbc393e3ac6fe4e4d766d (patch)
tree87dbcc99fdd9e66d3d55de32d5875792dd979518
parentcf0b1ab2e3e8eeef4ec63c051d6cdee7e2d47fa7 (diff)
downloadphp-git-f00753614789a37f18bdbc393e3ac6fe4e4d766d.tar.gz
# on working disk again
reverting code, moving to correct branch
-rw-r--r--ext/standard/url.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/ext/standard/url.c b/ext/standard/url.c
index e030a27203..99a6c5df60 100644
--- a/ext/standard/url.c
+++ b/ext/standard/url.c
@@ -361,45 +361,37 @@ static unsigned char hexchars[] = "0123456789ABCDEF";
*/
PHPAPI char *php_url_encode(char *s, int len, int *new_length)
{
- register unsigned char c;
- unsigned char *to, *from, *start;
- unsigned char *end;
-
- from = s;
- end = s + len;
- start = to = (unsigned char *) emalloc(3 * len + 1);
-
- while (from < end) {
- c = *from++;
+ register int x, y;
+ unsigned char *str;
- if (c == ' ') {
- *to++ = '+';
+ str = (unsigned char *) emalloc(3 * len + 1);
+ for (x = 0, y = 0; len--; x++, y++) {
+ str[y] = (unsigned char) s[x];
+ if (str[y] == ' ') {
+ str[y] = '+';
#ifndef CHARSET_EBCDIC
- } else if ((c < '0' && c != '-' && c != '.') ||
- (c < 'A' && c > '9') ||
- (c > 'Z' && c < 'a' && c != '_') ||
- (c > 'z')) {
- to[0] = '%';
- to[1] = hexchars[(unsigned char) c >> 4];
- to[2] = hexchars[(unsigned char) c & 15];
- to += 3;
+ } else if ((str[y] < '0' && str[y] != '-' && str[y] != '.') ||
+ (str[y] < 'A' && str[y] > '9') ||
+ (str[y] > 'Z' && str[y] < 'a' && str[y] != '_') ||
+ (str[y] > 'z')) {
+ str[y++] = '%';
+ str[y++] = hexchars[(unsigned char) s[x] >> 4];
+ str[y] = hexchars[(unsigned char) s[x] & 15];
+ }
#else /*CHARSET_EBCDIC*/
- } else if (!isalnum(c) && strchr("_-.", c) == NULL) {
+ } else if (!isalnum(str[y]) && strchr("_-.", str[y]) == NULL) {
/* Allow only alphanumeric chars and '_', '-', '.'; escape the rest */
- to[0] = '%';
- to[1] = hexchars[os_toascii[(unsigned char) c] >> 4];
- to[2] = hexchars[os_toascii[(unsigned char) c] & 15];
- to += 3;
-#endif /*CHARSET_EBCDIC*/
- } else {
- *to++ = c;
+ str[y++] = '%';
+ str[y++] = hexchars[os_toascii[(unsigned char) s[x]] >> 4];
+ str[y] = hexchars[os_toascii[(unsigned char) s[x]] & 0x0F];
}
+#endif /*CHARSET_EBCDIC*/
}
- *to = 0;
+ str[y] = '\0';
if (new_length) {
- *new_length = to - start;
+ *new_length = y;
}
- return (char *) start;
+ return ((char *) str);
}
/* }}} */