diff gen/mkutf.awk @ 24:23ceab03a393 1.0.0

unicode: remove uni_totitle While here, add more consts.
author David Demelier <markand@malikania.fr>
date Wed, 23 Mar 2022 13:17:10 +0100
parents 4983392b356f
children
line wrap: on
line diff
--- a/gen/mkutf.awk	Wed Mar 23 11:46:41 2022 +0100
+++ b/gen/mkutf.awk	Wed Mar 23 13:17:10 2022 +0100
@@ -81,7 +81,7 @@
 $3 == "Cc" { cntrlv[cntrlc++] = $1; }
 $3 == "Lu" { upperv[upperc++] = $1; tolowerv[uppercc++] = ($14 == "") ? $1 : $14; }
 $3 == "Ll" { lowerv[lowerc++] = $1; toupperv[lowercc++] = ($13 == "") ? $1 : $13; }
-$3 == "Lt" { titlev[titlec++] = $1; totitlev[lotitlecc++] = ($13 == "") ? $1 : $13;}
+$3 == "Lt" { titlev[titlec++] = $1; }
 $3 == "Nd" { digitv[digitc++] = $1; }
 
 END {
@@ -90,7 +90,7 @@
 	mkis("control", cntrlv, cntrlc, q, "");
 	mkis("upper", upperv, upperc, tolowerv, "lower");
 	mkis("lower", lowerv, lowerc, toupperv, "upper");
-	mkis("title", titlev, titlec, totitlev, "title");
+	mkis("title", titlev, titlec, q, "");
 	mkis("digit", digitv, digitc, q, "");
 }
 
@@ -104,7 +104,7 @@
 	return x;
 }
 
-# generate 'uni_is<name>' unicode lookup function
+# generate 'is<name>' unicode lookup function
 function mkis(name, runev, runec, casev, casename) {
 	rune1c = 0;
 	rune2c = 0;
@@ -189,7 +189,7 @@
 
 	#generate list of laces 1
 	if(rune3c > 0) {
-		print "static uint32_t "name"3[][2] = {";
+		print "static const uint32_t "name"3[][2] = {";
 		for(j = 0; j < rune3c; j++) {
 			print "\t{ 0x"rune3v0[j]", 0x"rune3v1[j]" },";
 		}
@@ -198,7 +198,7 @@
 
 	#generate list of laces 2
 	if(rune4c > 0) {
-		print "static uint32_t "name"4[][2] = {";
+		print "static const uint32_t "name"4[][2] = {";
 		for(j = 0; j < rune4c; j++) {
 			print "\t{ 0x"rune4v0[j]", 0x"rune4v1[j]" },";
 		}
@@ -208,12 +208,12 @@
 	# generate list of ranges
 	if(rune2c > 0) {
 		if(length(casev) > 0) {
-			print "static uint32_t "name"2[][3] = {";
+			print "static const uint32_t "name"2[][3] = {";
 			for(j = 0; j < rune2c; j++) {
 				print "\t{ 0x"rune2v0[j]", 0x"rune2v1[j]", 0x"case2v[j]" },";
 			}
 		} else {
-			print "static uint32_t "name"2[][2] = {"
+			print "static const uint32_t "name"2[][2] = {"
 			for(j = 0; j < rune2c; j++) {
 				print "\t{ 0x"rune2v0[j]", 0x"rune2v1[j]" },";
 			}
@@ -224,12 +224,12 @@
 	# generate list of singletons
 	if(rune1c > 0) {
 		if(length(casev) > 0) {
-			print "static uint32_t "name"1[][2] = {";
+			print "static const uint32_t "name"1[][2] = {";
 			for(j = 0; j < rune1c; j++) {
 				print "\t{ 0x"rune1v[j]", 0x"case1v[j]" },";
 			}
 		} else {
-			print "static uint32_t "name"1[] = {";
+			print "static const uint32_t "name"1[] = {";
 			for(j = 0; j < rune1c; j++) {
 				print "\t0x"rune1v[j]",";
 			}
@@ -260,25 +260,21 @@
 	if(length(casev) > 0) {
 		print "uint32_t\nuni_to"casename"(uint32_t r)\n{\n\tuint32_t *match;\n";
 		if(rune4c > 0) {
-			print "\tmatch = bsearch(&r, "name"4, nelem("name"4), sizeof *"name"4, &cmp2);\n";
-			print "\tif (match)";
+			print "\tif ((match = bsearch(&r, "name"4, nelem("name"4), sizeof *"name"4, &cmp2)))\n";
 			print "\t\treturn ((r - match[0]) % 2) ? r : r - 1;";
 		}
 		if(rune3c > 0) {
-			print "\tmatch = bsearch(&r, "name"3, nelem("name"3), sizeof *"name"3, &cmp2);\n";
-			print "\tif (match)";
+			print "\tif ((match = bsearch(&r, "name"3, nelem("name"3), sizeof *"name"3, &cmp2)))\n";
 			print "\t\treturn ((r - match[0]) % 2) ? r : r + 1;";
 		}
 		if(rune2c > 0) {
-			print "\tmatch = bsearch(&r, "name"2, nelem("name"2), sizeof *"name"2, &cmp2);\n";
-			print "\tif (match)";
+			print "\tif ((match = bsearch(&r, "name"2, nelem("name"2), sizeof *"name"2, &cmp2)))\n";
 			print "\t\treturn match[2] + (r - match[0]);";
 		}
 		if(rune1c > 0) {
-			print "\tmatch = bsearch(&r, "name"1, nelem("name"1), sizeof *"name"1, &cmp1);\n";
-			print "\tif (match)";
+			print "\tif ((match = bsearch(&r, "name"1, nelem("name"1), sizeof *"name"1, &cmp1)))\n";
 			print "\t\treturn match[1];";
 		}
-		print "\treturn r;\n}\n";
+		print "\n\treturn r;\n}\n";
 	}
 }