Name: Anonymous 2009-01-17 7:23
Using the encoding ranges specified in the following function
Write an equivalent function which can URL-encode a string in-place, i.e. assuming the buffer is large enough (thrice the length of the original string), a call such as
Your function cannot use any additional storage space that grows proportionally with the length of the string. The smallest, fastest, and most efficient implementations win.
URLencode(char *out, char *in) {
char a;
while((a=*in)) {
if((a>='A')&&(a<='Z')||(a>='a')&&(a<='z')||(a>='0')&&(a<='9')||(a=='-')||
(a=='_')||(a=='.')||(a=='~')) {
*(out++) = a;
} else {
sprintf(out,"%%%02x",a);
out+=3;
}
in++;
}
*out=0;
}Write an equivalent function which can URL-encode a string in-place, i.e. assuming the buffer is large enough (thrice the length of the original string), a call such as
URLencode(str) will write the URL-encoded version in the same buffer, possibly lengthened to up to thrice its original length.Your function cannot use any additional storage space that grows proportionally with the length of the string. The smallest, fastest, and most efficient implementations win.