libowfat/textcode/scan_urlencoded.c
leitner a8f6a1c121 remove special case stralloc textcode functions
write generic stralloc and array textcode wrapper functions
change textcode API to use long instead of int
add cescape fmt and scan functions to textcode
add fmt_foldwhitespace to textcode
2003-09-19 19:08:13 +00:00

26 lines
587 B
C

#include "fmt.h"
#include "textcode.h"
#include "scan.h"
unsigned long scan_urlencoded(const char *src,char *dest,unsigned long *destlen) {
register const unsigned char* s=(const unsigned char*) src;
unsigned long written=0,i;
for (i=0; s[i]; ++i) {
if (s[i]=='%') {
int j=scan_fromhex(s[i+1]);
if (j<0) break;
dest[written]=j<<4;
j=scan_fromhex(s[i+2]);
if (j<0) break;
dest[written]|=j;
i+=2;
} else if (s[i]=='+')
dest[written]=' ';
else
dest[written]=s[i];
++written;
}
*destlen=written;
return i;
}