aboutsummaryrefslogtreecommitdiff
path: root/gen/prop/bool-props.awk
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-04-05 14:26:33 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-04-05 14:26:33 +0200
commit450fd004b8f8358dc46e1bcc1bceae821f7ae158 (patch)
treec3e59514c6f6a9d5d94419f025748ce7c51a9e29 /gen/prop/bool-props.awk
parent0abf844cd9c22623e22f462c91f380f16524c7e8 (diff)
Add boolean properties to unicode/prop.h
Diffstat (limited to 'gen/prop/bool-props.awk')
-rw-r--r--gen/prop/bool-props.awk79
1 files changed, 79 insertions, 0 deletions
diff --git a/gen/prop/bool-props.awk b/gen/prop/bool-props.awk
new file mode 100644
index 0000000..d9c6299
--- /dev/null
+++ b/gen/prop/bool-props.awk
@@ -0,0 +1,79 @@
+BEGIN {
+ FS = "( *#.*| +; +)"
+
+ print "/* This file is autogenerated by gen/prop/bool-props; DO NOT EDIT. */"
+ print ""
+ print "#include \"__bsearch.h\""
+ print "#include \"bitset.h\""
+ print "#include \"rune.h\""
+ print "#include \"unicode/prop.h\""
+ print ""
+ print "/* clang-format off */"
+ print ""
+}
+
+$2 == prop || (prop == "Indic_Conjunct_Break" && $2 ~ /InCB;/) {
+ n = split($1, a, /\.\./)
+ lo = strtonum("0x" a[1])
+ hi = strtonum("0x" a[n])
+
+ for (i = lo; i <= hi; i++)
+ xs[i] = 1
+}
+
+END {
+ for (i = 0; i <= 0xFF; i++) {
+ if (xs[i])
+ mask = or(mask, lshift(1, i))
+ }
+
+ if (mask > 0) {
+ print "static constexpr bitset(bs, LATIN1_MAX) = {"
+ for (i = 0; i < 32; i++) {
+ if (i % 8 == 0)
+ printf "\t"
+ printf "0x%02X,", and(rshift(mask, 8 * i), 0xFF)
+ printf((i % 8 == 7) ? "\n" : " ")
+ }
+ print "};"
+ print ""
+ }
+
+ for (i = 0x100; i <= 0x10FFFF; i++) {
+ if (xs[i]) {
+ need_big_lookup = 1
+ break
+ }
+ }
+
+ if (need_big_lookup) {
+ print "static const struct {"
+ print "\trune lo, hi;"
+ print "} lookup[] = {"
+
+ for (i = 0x100; i <= 0x10FFFF; i++) {
+ if (!xs[i])
+ continue
+ lo = i
+ while (xs[i + 1])
+ i++
+ printf "\t{RUNE_C(0x%06X), RUNE_C(0x%06X)},\n", lo, i
+ }
+
+ print "};"
+ print ""
+ print "__MLIB_DEFINE_BSEARCH_CONTAINS(lookup)"
+ print ""
+ }
+
+ print "bool"
+ printf "uprop_is_%s(rune ch)\n", short
+ print "{"
+ if (mask > 0 && need_big_lookup)
+ print "\treturn ch <= LATIN1_MAX ? TESTBIT(bs, ch) : mlib_lookup_contains(ch);"
+ else if (need_big_lookup)
+ print "\treturn mlib_lookup_contains(ch);"
+ else
+ print "\treturn ch <= LATIN1_MAX && TESTBIT(bs, ch);"
+ print "}"
+}