Mercurial > repo
changeset 6342:8e6c7372226d
<\oren\> fetch http://www.orenwatson.be/u8tbl.c
author | HackBot |
---|---|
date | Sat, 28 Nov 2015 15:33:08 +0000 |
parents | 0906f101bbf5 |
children | 99c924481a77 |
files | u8tbl.c |
diffstat | 1 files changed, 45 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/u8tbl.c Sat Nov 28 15:33:08 2015 +0000 @@ -0,0 +1,45 @@ +#include "stdio.h" +#include "stdlib.h" + +char *int2u8(unsigned U){ + static char out[7]; + int i=0; + if(U<=0x80)out[i++]=U; + else if(U<0x800){ + out[i++]=(U>>6|0xC0); + out[i++]=(U&0x3f|0x80); + }else if(U<=0x10000){ + out[i++]=(U>>12|0xE0); + out[i++]=(U>>6&0x3f|0x80); + out[i++]=(U&0x3f|0x80); + }else if(U<=0x200000){ + out[i++]=(U>>18|0xF0); + out[i++]=(U>>12&0x3f|0x80); + out[i++]=(U>>6&0x3f|0x80); + out[i++]=(U&0x3f|0x80); + }else if(U<=0x4000000){ + out[i++]=(U>>24|0xF8); + out[i++]=(U>>18&0x3f|0x80); + out[i++]=(U>>12&0x3f|0x80); + out[i++]=(U>>6&0x3f|0x80); + out[i++]=(U&0x3f|0x80); + }else if(U<=0x80000000){ + out[i++]=(U>>30|0xFC); + out[i++]=(U>>24&0x3f|0x80); + out[i++]=(U>>18&0x3f|0x80); + out[i++]=(U>>12&0x3f|0x80); + out[i++]=(U>>6&0x3f|0x80); + out[i++]=(U&0x3f|0x80); + } + out[i]=0; + return out; +} + +int main(int argc,char **argv){ + int i = strtol(argv[1],0,0); + int m = strtol(argv[2],0,0); + for(;i<=m;i++){ + printf("%s",int2u8(i)); + if(i%16==15)putchar('\n'); + } +}