Debian Codegraph @

generate/Unicode/UCD_features_generated_h.praat

raw
1 # UCD_features_generated_h.praat
2 # Paul Boersma 2018,2019,2022,2024,2025
3
4 Text writing preferences: "UTF-8"
5
6 table = Read Table from semicolon-separated file: "UnicodeData 16.0.txt"
7 numberOfRows = Get number of rows
8
9 stopwatch
10 outfile$ = "UCD_features_generated.h"
11 writeFileLine: outfile$, "/* This file was generated automatically by generate/Unicode/UCD_features_generated_h.praat */"
12
13 previousLineCodePoint = -1
14 for irow from 1 to numberOfRows
15 code$ = Get value: irow, "code"
16 lineCodePoint = number ("0x" + code$)
17 goto finished lineCodePoint > 0x2FFFF
18 while lineCodePoint > previousLineCodePoint + 1
19 previousLineCodePoint += 1
20 if isFirst
21 line$ = "/* " + hexadecimal$ (previousLineCodePoint, 4) + " " + (name$ - "First>" + "Next>") + " */" + newline$
22 line$ += tab$ + "{ " + categoryFeature$ +
23 ... ", 0x" + hexadecimal$ (previousLineCodePoint, 4) + ", 0x" + hexadecimal$ (previousLineCodePoint, 4) +
24 ... ", 0x" + hexadecimal$ (previousLineCodePoint, 4) + ", nullptr, '\0', '\0' }," + newline$
25 else
26 line$ = "/* " + hexadecimal$ (previousLineCodePoint, 4) + " UNASSIGNED */" + newline$
27 line$ += tab$ + "{ kUCD_UNASSIGNED " +
28 ... ", 0x" + hexadecimal$ (previousLineCodePoint, 4) + ", 0x" + hexadecimal$ (previousLineCodePoint, 4) +
29 ... ", 0x" + hexadecimal$ (previousLineCodePoint, 4) + ", nullptr, '\0', '\0' }," + newline$
30 endif
31 appendFile: outfile$, line$
32 endwhile
33 name$ = Get value: irow, "name"
34 isFirst = ( index (name$, " First>") <> 0 )
35 categoryCode$ = Get value: irow, "category"
36 alternativeName$ = Get value: irow, "dum1"
37 upper$ = Get value: irow, "upper"
38 lower$ = Get value: irow, "lower"
39 title$ = Get value: irow, "title"
40 decomp$ = Get value: irow, "decomp"
41 symbol$ = if lineCodePoint >= 0xD800 and lineCodePoint <= 0xDFFF
42 ... then " SURROGATE " else unicode$ (lineCodePoint) fi
43 line$ = "/* " + code$ + " " +
44 ... if name$ <> "<control>" then "(x" + symbol$ + "x) " else "" fi +
45 ... name$ + " " +
46 ... if alternativeName$ <> "" then "(" + alternativeName$ + ") " else "" fi +
47 ... "*/" + newline$
48 majorCategoryCode$ = mid$ (categoryCode$, 1, 1)
49 minorCategoryCode$ = mid$ (categoryCode$, 2, 1)
50 if majorCategoryCode$ = "L"
51 categoryFeature$ = "mUCD_WORD_CHARACTER"
52 if minorCategoryCode$ = "u"
53 categoryFeature$ += " | mUCD_UPPERCASE_LETTER"
54 elsif minorCategoryCode$ = "l"
55 categoryFeature$ += " | mUCD_LOWERCASE_LETTER"
56 elsif minorCategoryCode$ = "t"
57 categoryFeature$ += " | mUCD_TITLECASE_LETTER"
58 elsif minorCategoryCode$ = "m"
59 categoryFeature$ += " | mUCD_MODIFIER_LETTER"
60 elsif minorCategoryCode$ = "o"
61 categoryFeature$ += " | mUCD_OTHER_LETTER"
62 else
63 exitScript: "Unknown letter category code in row ", irow, "."
64 endif
65 elsif majorCategoryCode$ = "M"
66 categoryFeature$ = "mUCD_WORD_CHARACTER"
67 if minorCategoryCode$ = "n"
68 categoryFeature$ += " | mUCD_NONSPACING_MARK"
69 elsif minorCategoryCode$ = "c"
70 categoryFeature$ += " | mUCD_SPACING_MARK"
71 elsif minorCategoryCode$ = "e"
72 categoryFeature$ += " | mUCD_ENCLOSING_MARK"
73 else
74 exitScript: "Unknown mark category code in row ", irow, "."
75 endif
76 elsif majorCategoryCode$ = "N"
77 categoryFeature$ = "mUCD_WORD_CHARACTER"
78 if minorCategoryCode$ = "d"
79 categoryFeature$ += " | mUCD_DECIMAL_NUMBER"
80 elsif minorCategoryCode$ = "l"
81 categoryFeature$ += " | mUCD_LETTER_NUMBER"
82 elsif minorCategoryCode$ = "o"
83 categoryFeature$ += " | mUCD_OTHER_NUMBER"
84 else
85 exitScript: "Unknown number category code in row ", irow, "."
86 endif
87 elsif majorCategoryCode$ = "P"
88 if minorCategoryCode$ = "c"
89 categoryFeature$ = "mUCD_WORD_CHARACTER | mUCD_CONNECTOR_PUNCTUATION"
90 elsif minorCategoryCode$ = "d"
91 categoryFeature$ = "mUCD_DASH_PUNCTUATION"
92 elsif minorCategoryCode$ = "s"
93 categoryFeature$ = "mUCD_OPEN_PUNCTUATION"
94 elsif minorCategoryCode$ = "e"
95 categoryFeature$ = "mUCD_CLOSE_PUNCTUATION"
96 elsif minorCategoryCode$ = "i"
97 categoryFeature$ = "mUCD_INITIAL_PUNCTUATION"
98 elsif minorCategoryCode$ = "f"
99 categoryFeature$ = "mUCD_FINAL_PUNCTUATION"
100 elsif minorCategoryCode$ = "o"
101 categoryFeature$ = "mUCD_OTHER_PUNCTUATION"
102 else
103 exitScript: "Unknown punctuation category code in row ", irow, "."
104 endif
105 elsif majorCategoryCode$ = "S"
106 if minorCategoryCode$ = "m"
107 categoryFeature$ = "mUCD_MATH_SYMBOL"
108 elsif minorCategoryCode$ = "c"
109 categoryFeature$ = "mUCD_CURRENCY_SYMBOL"
110 elsif minorCategoryCode$ = "k"
111 categoryFeature$ = "mUCD_MODIFIER_SYMBOL"
112 elsif minorCategoryCode$ = "o"
113 categoryFeature$ = "mUCD_OTHER_SYMBOL"
114 else
115 exitScript: "Unknown symbol category code in row ", irow, "."
116 endif
117 elsif majorCategoryCode$ = "Z"
118 if minorCategoryCode$ = "s"
119 if lineCodePoint = 0x00A0 or lineCodePoint = 0x202F
120 categoryFeature$ = "mUCD_NON_BREAKING_SPACE"
121 else
122 categoryFeature$ = "mUCD_BREAKING_SPACE"
123 endif
124 elsif minorCategoryCode$ = "l"
125 categoryFeature$ = "mUCD_LINE_SEPARATOR"
126 elsif minorCategoryCode$ = "p"
127 categoryFeature$ = "mUCD_PARAGRAPH_SEPARATOR"
128 else
129 exitScript: "Unknown separator category code in row ", irow, "."
130 endif
131 elsif majorCategoryCode$ = "C"
132 if minorCategoryCode$ = "c"
133 categoryFeature$ = "mUCD_CONTROL"
134 #
135 # Special cases that diverge from UnicodeData.txt.
136 #
137 if lineCodePoint = 0
138 categoryFeature$ += " | mUCD_NULL"
139 elsif lineCodePoint = 9 ; tab
140 categoryFeature$ += " | mUCD_BREAKING_SPACE"
141 elsif (lineCodePoint >= 10 and lineCodePoint <= 13) or lineCodePoint = 0x0085 ; line feed, vertical tab, form feed, carriage return, next line
142 categoryFeature$ += " | mUCD_LINE_SEPARATOR"
143 endif
144 elsif minorCategoryCode$ = "f"
145 categoryFeature$ = "mUCD_FORMAT"
146 elsif minorCategoryCode$ = "s"
147 categoryFeature$ = "kUCD_UNASSIGNED"
148 elsif minorCategoryCode$ = "o"
149 categoryFeature$ = "mUCD_PRIVATE_USE"
150 elsif minorCategoryCode$ = "n"
151 categoryFeature$ = "kUCD_UNASSIGNED"
152 else
153 exitScript: "Unknown other category code in row ", irow, "."
154 endif
155 else
156 categoryFeature$ = "0"
157 endif
158 lower$ = if lower$ = "" then code$ else lower$ fi
159 upper$ = if upper$ = "" then code$ else upper$ fi
160 title$ = if title$ = "" then code$ else title$ fi
161 if decomp$ = ""
162 decomp$ = "nullptr"
163 elsif index (decomp$, "<")
164 decomp$ = "nullptr"
165 elsif index (decomp$, " ") = 0
166 decomp$ = "nullptr"
167 else
168 decomp$ = "U""\u" + replace$ (decomp$, " ", "\u", 0) + """"
169 endif
170 line$ += tab$ + "{ " + categoryFeature$ +
171 ... ", 0x" + upper$ + ", 0x" + lower$ + ", 0x" + title$ + ", " + decomp$ + ", '\0', '\0' }," + newline$
172 appendFile: outfile$, line$
173 previousLineCodePoint = lineCodePoint
174 endfor
175
176 label finished
177 appendInfoLine: stopwatch