plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

urlfmt.c (425B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include <bin.h>
      4 #include <httpd.h>
      5 
      6 int
      7 hurlfmt(Fmt *f)
      8 {
      9 	char buf[HMaxWord*2];
     10 	Rune r;
     11 	char *s;
     12 	int t;
     13 
     14 	s = va_arg(f->args, char*);
     15 	for(t = 0; t < sizeof(buf) - 8; ){
     16 		s += chartorune(&r, s);
     17 		if(r == 0)
     18 			break;
     19 		if(r <= ' ' || r == '%' || r >= Runeself)
     20 			t += snprint(&buf[t], sizeof(buf)-t, "%%%2.2x", r);
     21 		else
     22 			buf[t++] = r;
     23 	}
     24 	buf[t] = 0;
     25 	return fmtstrcpy(f, buf);
     26 }