Plan 9 from Bell Labs’s /usr/web/sources/contrib/quanstro/src/runetype/test.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>

const char* tf(int i){
	if (i){
		return "t";
	}
	return "";
}

int utftod(const char* s){
	int l;
	int b;
	Rune r;
	int t;

	t=0;
	for(l=strlen(s); *s; s+=b, l-=b){
		b = chartorune(&r, (char*)s);
		if (0 == b){
			break;
		}
		t = t*10 + digitrunevalue(r);
	}
	return t;
}

int convert(const char* s, Rune (*R)(Rune)){
	int l;
	int b;
	Rune r;
	int t;

	t=0;
	for(l=strlen(s); *s; s+=b, l-=b){
		b = chartorune(&r, (char*)s);
		if (0 == b){
			break;
		}
		print("%C", R(r));
	}
	return t;
}

void main(int c, char**v){
	int l;
	int b;
	Rune r;
	char* s;
	int number;
	char ult[UTFmax*3 + sizeof("//\0")];

	if (*v){
		print ("%C\t%6s\t%6s\t%6s\t%6s\t%6s\t%6s\t%6s\n", 0x24d0, "digit", "alpha", "upper", "lower", "title", "space", "u/l/t");
	}
	for(++v; *v; v++){
		s = *v;
		l=strlen(s);
		number=1;
		for(; *s; s += b, l-=b){
			b=chartorune(&r, s);
			if (0 == b){
				break;
			}
			if (number){
				number &= isdigitrune(r);
			}

			snprint(ult, sizeof(ult), "%C/%C/%C", tolowerrune(r), toupperrune(r), totitlerune(r));

			print ("%C\t" "%6s\t%6s\t%6s\t%6s\t%6s\t%6s\t%6s\n", r,
				tf(isdigitrune(r)),
				tf(isalpharune(r)),
				tf(isupperrune(r)),
				tf(islowerrune(r)),
				tf(istitlerune(r)),
				tf(isspacerune(r)),
				ult
			);

		}

		if (number){
			print("%d\t", utftod(*v));
		}
		convert(*v, toupperrune);
		print("\t");
		convert(*v, tolowerrune);
		print("\t");
		convert(*v, totitlerune);
		print("\n");

	}
	exits("");
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.