view src/u8tbl.c @ 9954:fb3529990ed4

<oerjan> ` echo \'121:122 194:196 770:771 1000:1001 1493 1497 2113:2114 3341:3343 4530:4531 5136:5137 5642:5643 5895 5897 8669:8678 9070:9071 9074:9075\' | xargs -n 1 >share/scowrevs
author HackBot
date Mon, 12 Dec 2016 03:24:20 +0000
parents 8ddd6d5dc480
children
line wrap: on
line source

#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');
	}
}