Sample Code

I wrote this in C to fit my particular use case. Details of url encoding can vary

/* urlencode.c */
/* encode from stdin to stdout */

#include <stdio.h>
#include <ctype.h>

char html5[256] = {
/* 0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F    */
   0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , /* 00-0F */
   0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , /* 10-0F */
  43 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 ,  0 , 42 ,  0 ,  0 , 45 , 46 ,  0 , /* 20-0F */
  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',  0 ,  0 ,  0 ,  0 ,  0 ,  0 , /* 30-0F */
   0 , 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', /* 40-0F */
  'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',  0 ,  0 ,  0 ,  0 ,  0 , /* 50-0f */
   0 , 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', /* 60-0F */
  'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',  0 ,  0 ,  0 ,  0 ,  0 , /* 70-0F */
   0 };

void urlencode( FILE * in, FILE * out) {

    int s;

    while( ( s=fgetc( in ) ) != EOF ) {

        if (html5[s]) fputc( html5[s], out );
        else fprintf( out, "%%%02X", s);
    }
}


int main( ) {
	urlencode( stdin, stdout );
}

Notes