comparison u8tbl.c @ 6342:8e6c7372226d

<\oren\> fetch http://www.orenwatson.be/u8tbl.c
author HackBot
date Sat, 28 Nov 2015 15:33:08 +0000
parents
children
comparison
equal deleted inserted replaced
6341:0906f101bbf5 6342:8e6c7372226d
1 #include "stdio.h"
2 #include "stdlib.h"
3
4 char *int2u8(unsigned U){
5 static char out[7];
6 int i=0;
7 if(U<=0x80)out[i++]=U;
8 else if(U<0x800){
9 out[i++]=(U>>6|0xC0);
10 out[i++]=(U&0x3f|0x80);
11 }else if(U<=0x10000){
12 out[i++]=(U>>12|0xE0);
13 out[i++]=(U>>6&0x3f|0x80);
14 out[i++]=(U&0x3f|0x80);
15 }else if(U<=0x200000){
16 out[i++]=(U>>18|0xF0);
17 out[i++]=(U>>12&0x3f|0x80);
18 out[i++]=(U>>6&0x3f|0x80);
19 out[i++]=(U&0x3f|0x80);
20 }else if(U<=0x4000000){
21 out[i++]=(U>>24|0xF8);
22 out[i++]=(U>>18&0x3f|0x80);
23 out[i++]=(U>>12&0x3f|0x80);
24 out[i++]=(U>>6&0x3f|0x80);
25 out[i++]=(U&0x3f|0x80);
26 }else if(U<=0x80000000){
27 out[i++]=(U>>30|0xFC);
28 out[i++]=(U>>24&0x3f|0x80);
29 out[i++]=(U>>18&0x3f|0x80);
30 out[i++]=(U>>12&0x3f|0x80);
31 out[i++]=(U>>6&0x3f|0x80);
32 out[i++]=(U&0x3f|0x80);
33 }
34 out[i]=0;
35 return out;
36 }
37
38 int main(int argc,char **argv){
39 int i = strtol(argv[1],0,0);
40 int m = strtol(argv[2],0,0);
41 for(;i<=m;i++){
42 printf("%s",int2u8(i));
43 if(i%16==15)putchar('\n');
44 }
45 }