Debian Codegraph @

intl/icu/source/data/brkitr/rules/line_phrase_cj.txt

raw
1 # Copyright (C) 2022 and later: Unicode, Inc. and others.
2 # License & terms of use: http://www.unicode.org/copyright.html
3 #
4 # file: line_phrase_cj.txt
5 #
6 # Line Breaking Rules
7 # Implement default line breaking as defined by
8 # Unicode Standard Annex #14 (https://www.unicode.org/reports/tr14/)
9 # for Unicode 14.0, with the following modification:
10 #
11 # Boundaries between hyphens and following letters are suppressed when
12 # there is a boundary preceding the hyphen. See rule 20.9
13 #
14 # This corresponds to CSS line-break-word-handling=phrase (BCP47 -u-lw-phrase).
15 # It sets characters of class CJ to behave like NS.
16 # It allows breaking before 201C and after 201D, for zh_Hans, zh_Hant, and ja.
17 #
18 # The content is the same as line_cj.txt except the following
19 # 1. Add CJK into dictionary.
20 # 2. Add East Asian Width with class F, W and H into $ALPlus.
21 #
22 # Character Classes defined by TR 14.
23 #
24
25 !!chain;
26 !!quoted_literals_only;
27
28 $AI = [:LineBreak = Ambiguous:];
29 $AK = [:LineBreak = Aksara:];
30 $AL = [:LineBreak = Alphabetic:];
31 $AP = [:LineBreak = Aksara_Prebase:];
32 $AS = [:LineBreak = Aksara_Start:];
33 $BA = [:LineBreak = Break_After:];
34 $HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA.
35 $BB = [:LineBreak = Break_Before:];
36 $BK = [:LineBreak = Mandatory_Break:];
37 $B2 = [:LineBreak = Break_Both:];
38 $CB = [:LineBreak = Contingent_Break:];
39 $CJ = [:LineBreak = Conditional_Japanese_Starter:];
40 $CL = [[:LineBreak = Close_Punctuation:] \u201d];
41 # $CM = [:LineBreak = Combining_Mark:];
42 $CP = [:LineBreak = Close_Parenthesis:];
43 $CR = [:LineBreak = Carriage_Return:];
44 $EB = [:LineBreak = EB:];
45 $EM = [:LineBreak = EM:];
46 $EX = [:LineBreak = Exclamation:];
47 $GL = [:LineBreak = Glue:];
48 $HL = [:LineBreak = Hebrew_Letter:];
49 $HY = [:LineBreak = Hyphen:];
50 $H2 = [:LineBreak = H2:];
51 $H3 = [:LineBreak = H3:];
52 $ID = [:LineBreak = Ideographic:];
53 $IN = [:LineBreak = Inseperable:];
54 $IS = [:LineBreak = Infix_Numeric:];
55 $JL = [:LineBreak = JL:];
56 $JV = [:LineBreak = JV:];
57 $JT = [:LineBreak = JT:];
58 $LF = [:LineBreak = Line_Feed:];
59 $NL = [:LineBreak = Next_Line:];
60 # NS includes CJ for CSS strict line breaking.
61 $NS = [[:LineBreak = Nonstarter:] $CJ];
62 $NU = [:LineBreak = Numeric:];
63 $OP = [[:LineBreak = Open_Punctuation:] \u201c];
64 $PO = [:LineBreak = Postfix_Numeric:];
65 $PR = [:LineBreak = Prefix_Numeric:];
66 $QU = [[:LineBreak = Quotation:] - [\u201c\u201d]];
67 $RI = [:LineBreak = Regional_Indicator:];
68 $SA = [:LineBreak = Complex_Context:];
69 $SG = [:LineBreak = Surrogate:];
70 $SP = [:LineBreak = Space:];
71 $SY = [:LineBreak = Break_Symbols:];
72 $VF = [:LineBreak = Virama_Final:];
73 $VI = [:LineBreak = Virama:];
74 $WJ = [:LineBreak = Word_Joiner:];
75 $XX = [:LineBreak = Unknown:];
76 $ZW = [:LineBreak = ZWSpace:];
77 $ZWJ = [:LineBreak = ZWJ:];
78
79 $EastAsian = [\p{ea=F}\p{ea=W}\p{ea=H}];
80
81 $ExtPictUnassigned = [\p{Extended_Pictographic} & \p{Cn}];
82
83 # By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly
84 # list it in the numerous rules that use CM.
85 # By LB1, SA characters with general categor of Mn or Mc also resolve to CM.
86
87 $CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]];
88 $CMX = [[$CM] - [$ZWJ]];
89
90 # Dictionary character set, for triggering language-based break engines. Currently
91 # limited to LineBreak=Complex_Context (SA) and $dictionaryCJK.
92
93 # Add CJK dictionary
94 $Han = [:Han:];
95 $Katakana = [:Katakana:];
96 $Hiragana = [:Hiragana:];
97 $HangulSyllable = [\uac00-\ud7a3];
98 $ComplexContext = [:LineBreak = Complex_Context:];
99 $KanaKanji = [$Han $Hiragana $Katakana \u30fc];
100 $dictionaryCJK = [$KanaKanji $HangulSyllable];
101 $dictionary = [$ComplexContext $dictionaryCJK];
102
103
104 #
105 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
106 # SA (Dictionary chars, excluding Mn and Mc)
107 # SG (Unpaired Surrogates)
108 # XX (Unknown, unassigned)
109 # as $AL (Alphabetic)
110 #
111 # Let fullwidth-ASCII digits and letters be part of words.
112 $FW_alphanum = [\uff10-\uff19\uff21-\uff3a\uff41-\uff5a];
113 $ALPlus = [$AL $AI $SG $XX $FW_alphanum [$dictionary-[[:Mn:][:Mc:]]]];
114
115
116 ## -------------------------------------------------
117
118 #
119 # CAN_CM is the set of characters that may combine with CM combining chars.
120 # Note that Linebreak UAX 14's concept of a combining char and the rules
121 # for what they can combine with are _very_ different from the rest of Unicode.
122 #
123 # Note that $CM itself is left out of this set. If CM is needed as a base
124 # it must be listed separately in the rule.
125 #
126 $CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs
127 $CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs
128
129 #
130 # AL_FOLLOW set of chars that can unconditionally follow an AL
131 # Needed in rules where stand-alone $CM s are treated as AL.
132 #
133 $AL_FOLLOW = [$BK $CR $LF $NL $ZW $SP $CL $CP $EX $HL $IS $SY $WJ $GL [$OP - $EastAsian] $QU $BA $HY $NS $IN $NU $PR $PO $ALPlus];
134
135
136 #
137 # Rule LB 4, 5 Mandatory (Hard) breaks.
138 #
139 $LB4Breaks = [$BK $CR $LF $NL];
140 $LB4NonBreaks = [^$BK $CR $LF $NL $CM];
141 $CR $LF {100};
142
143 #
144 # LB 6 Do not break before hard line breaks.
145 #
146 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
147 $CAN_CM $CM* $LB4Breaks {100};
148 ^$CM+ $LB4Breaks {100};
149
150 # LB 7 x SP
151 # x ZW
152 $LB4NonBreaks [$SP $ZW];
153 $CAN_CM $CM* [$SP $ZW];
154 ^$CM+ [$SP $ZW];
155
156 #
157 # LB 8 Break after zero width space
158 # ZW SP* ÷
159 #
160 $LB8Breaks = [$LB4Breaks $ZW];
161 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
162 $ZW $SP* / [^$SP $ZW $LB4Breaks];
163
164 # LB 8a ZWJ x Do not break Emoji ZWJ sequences.
165 #
166 $ZWJ [^$CM];
167
168 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
169 # $CM not covered by the above needs to behave like $AL
170 # See definition of $CAN_CM.
171
172 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
173 ^$CM+;
174
175 #
176 # LB 11 Do not break before or after WORD JOINER & related characters.
177 #
178 $CAN_CM $CM* $WJ;
179 $LB8NonBreaks $WJ;
180 ^$CM+ $WJ;
181
182 $WJ $CM* .;
183
184 #
185 # LB 12 Do not break after NBSP and related characters.
186 # GL x
187 #
188 $GL $CM* .;
189
190 #
191 # LB 12a Do not break before NBSP and related characters ...
192 # [^SP BA HY] x GL
193 #
194 [[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GL;
195 ^$CM+ $GL;
196
197
198
199
200 # LB 13 Don't break before ']' or '!' or '/', even after spaces.
201 #
202 $LB8NonBreaks $CL;
203 $CAN_CM $CM* $CL;
204 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
205
206 $LB8NonBreaks $CP;
207 $CAN_CM $CM* $CP;
208 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
209
210 $LB8NonBreaks $EX;
211 $CAN_CM $CM* $EX;
212 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
213
214 $LB8NonBreaks $SY;
215 $CAN_CM $CM* $SY;
216 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
217
218
219 #
220 # LB 14 Do not break after OP, even after spaces
221 # Note subtle interaction with "SP IS /" rules in LB14a.
222 # This rule consumes the SP, chaining happens on the IS, effectivley overriding the SP IS rules,
223 # which is the desired behavior.
224 #
225 $OP $CM* $SP* .;
226
227 $OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
228 # by rule 8, CM following a SP is stand-alone.
229
230
231 # LB 15a
232 ($OP $CM* $SP+ | [$OP $QU $GL] $CM*) ([\p{Pi} & $QU] $CM* $SP*)+ .;
233 ($OP $CM* $SP+ | [$OP $QU $GL] $CM*) ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?;
234 ^([\p{Pi} & $QU] $CM* $SP*)+ .;
235 ^([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?;
236
237 # LB 15b
238 $LB8NonBreaks [\p{Pf} & $QU] $CM* [$SP $GL $WJ $CL $QU $CP $EX $IS $SY $BK $CR $LF $NL $ZW {eof}];
239 $CAN_CM $CM* [\p{Pf} & $QU] $CM* [$SP $GL $WJ $CL $QU $CP $EX $IS $SY $BK $CR $LF $NL $ZW {eof}];
240 ^$CM+ [\p{Pf} & $QU] $CM* [$SP $GL $WJ $CL $QU $CP $EX $IS $SY $BK $CR $LF $NL $ZW {eof}];
241
242 # Messy interaction: manually chain between LB 15b and LB 15a on Pf Pi.
243 $LB8NonBreaks [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ .;
244 $LB8NonBreaks [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?;
245 $CAN_CM $CM* [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ .;
246 $CAN_CM $CM* [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?;
247 ^$CM+ [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ .;
248 ^$CM+ [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?;
249
250
251 # LB 15c Force a break before start of a number with a leading decimal pt, e.g. " .23"
252 # Note: would be simpler to express as "$SP / $IS $CM* $NU;", but ICU rules have limitations.
253 # See issue ICU-20303
254
255
256 $CanFollowIS = [$BK $CR $LF $NL $SP $ZW $WJ $GL $CL $CP $EX $IS $SY $QU $BA $HY $NS $ALPlus $HL $IN];
257 $SP $IS / [^ $CanFollowIS $NU $CM];
258 $SP $IS $CM* $CMX / [^ $CanFollowIS $NU $CM];
259
260 #
261 # LB 15d Do not break before numeric separators (IS), even after spaces.
262 # SP IS QU is handled below as part of LB 19.
263
264 [$LB8NonBreaks - $SP] $IS;
265 $SP $IS $CM* [$CanFollowIS {eof}];
266 $SP $IS $CM* $ZWJ [^$CM $NU];
267
268 $CAN_CM $CM* $IS;
269 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
270
271
272 # LB 16
273 ($CL | $CP) $CM* $SP* $NS;
274
275 # LB 17
276 $B2 $CM* $SP* $B2;
277
278 #
279 # LB 18 Break after spaces.
280 #
281 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
282 $LB18Breaks = [$LB8Breaks $SP];
283
284
285 # LB 19 and LB 19a.
286 # Instead of implementing both as keep-together rules as in UAX #14, we have an
287 # East_Asian_Width and General_Category-insensitive keep-together rule
288 # equivalent to the old LB19 × QU and QU ×, and then we poke holes into it based
289 # on context. This avoids having to do manual chaining over multiple characters
290 # with many other rules over multiple characters, as a keep-together LB19a would
291 # overlap in context with at least LB14, LB15a, LB15a, LB15d, LB30a, and itself.
292 $LB18NonBreaks $CM* $QU;
293 ^$CM+ $QU;
294
295 [$LB18NonBreaks & $EastAsian - [$OP $GL]] / [\p{Pi} & $QU] $CM* [ $EastAsian - $CM];
296 [$LB18NonBreaks & $EastAsian - [$OP $GL]] $CM* $CMX / [\p{Pi} & $QU] $CM* [ $EastAsian - $CM];
297
298 $QU $CM* .;
299 [$LB18NonBreaks & $EastAsian] $CM* [\p{Pf} & $QU] / [ $EastAsian - [$NS $BA $EX $CL $IN $IS $GL $CM]];
300 [$LB18NonBreaks & $EastAsian] $CM* [\p{Pf} & $QU] $CM* $CMX / [ $EastAsian - [$NS $BA $EX $CL $IN $IS $GL $CM]];
301
302 # LB 20
303 # <break> $CB
304 # $CB <break>
305 #
306 $LB20NonBreaks = [$LB18NonBreaks - $CB];
307
308 # LB 20a Don't break between Hyphens and Letters when there is a break preceding the hyphen.
309 # Originally added as a Finnish tailoring, promoted to default ICU behavior (ICU-8151),
310 # and then to default UAX #14 behaviour (UTC-179-C32).
311 #
312 ^($HY | $HH) $CM* $ALPlus;
313 $GL $CM* ($HY | $HH) $CM* $ALPlus;
314 # Non-breaking CB from LB8a:
315 $CB $CM* $ZWJ ($HY | $HH) $CM* $ALPlus;
316 # Non-breaking SP from LB14:
317 $OP $CM* $SP+ ($HY | $HH) $CM* $ALPlus;
318 # Non-breaking SP from LB15a:
319 ($OP $CM* $SP+ | [$OP $QU $GL] $CM*) ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* $ALPlus;
320 ^([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* $ALPlus;
321 # Non-breaking SP from LB15a following LB15b:
322 $LB8NonBreaks [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* $ALPlus;
323 $CAN_CM $CM* [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* $ALPlus;
324 ^$CM+ [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* $ALPlus;
325
326 # LB 21 x (BA | HY | NS)
327 # BB x
328 #
329 $LB20NonBreaks $CM* ($BA | $HY | $NS);
330
331
332 ^$CM+ ($BA | $HY | $NS);
333
334 $BB $CM* [^$CB]; # $BB x
335 $BB $CM* $LB20NonBreaks;
336
337 # LB 21a Do not break after the hyphen in Hebrew + Hyphen + non-Hebrew
338 # HL (HY | BA) x [^HL]
339 #
340 $HL $CM* ($HY | [ $BA - $EastAsian ] ) $CM* [^$CB $HL]?;
341
342 # LB 21b (forward) Don't break between SY and HL
343 # (break between HL and SY already disallowed by LB 13 above)
344 $SY $CM* $HL;
345
346 # LB 22 Do not break before ellipses
347 #
348 $LB20NonBreaks $CM* $IN;
349 ^$CM+ $IN;
350
351
352 # LB 23
353 #
354 ($ALPlus | $HL) $CM* $NU;
355 ^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL
356 $NU $CM* ($ALPlus | $HL);
357
358 # LB 23a
359 #
360 $PR $CM* ($ID | $EB | $EM);
361 ($ID | $EB | $EM) $CM* $PO;
362
363
364 #
365 # LB 24
366 #
367 ($PR | $PO) $CM* ($ALPlus | $HL);
368 ($ALPlus | $HL) $CM* ($PR | $PO);
369 ^$CM+ ($PR | $PO); # Rule 10, any otherwise unattached CM behaves as AL
370
371 #
372 # LB 25 Numbers.
373 #
374 (($PR | $PO) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))*
375 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?;
376
377 # LB 26 Do not break a Korean syllable
378 #
379 $JL $CM* ($JL | $JV | $H2 | $H3);
380 ($JV | $H2) $CM* ($JV | $JT);
381 ($JT | $H3) $CM* $JT;
382
383 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
384 ($JL | $JV | $JT | $H2 | $H3) $CM* $PO;
385 $PR $CM* ($JL | $JV | $JT | $H2 | $H3);
386
387
388 # LB 28 Do not break between alphabetics
389 #
390 ($ALPlus | $HL) $CM* ($ALPlus | $HL);
391 ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL
392
393 #LB 28a Do not break Orthographic syllables
394 ($AP $CM*)? ($AS | $AK | [◌] ) ($CM* $VI $CM* ($AK | [◌] ))* ($CM* $VI | (($CM* ($AS | $AK | [◌] ) )? $CM* $VF))?;
395
396 # LB 29
397 $IS $CM* ($ALPlus | $HL);
398
399 # LB 30
400 ($ALPlus | $HL | $NU) $CM* [$OP - $EastAsian];
401 ^$CM+ [$OP - $EastAsian]; # The $CM+ is from rule 10, an unattached CM is treated as AL.
402 [$CP - $EastAsian] $CM* ($ALPlus | $HL | $NU);
403
404 # LB 30a Do not break between regional indicators. Break after pairs of them.
405 # Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM.
406 $RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $CM]];
407 $RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $CM]];
408 $RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $ZWJ {eof}];
409 # note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?'
410 # because of the chain-out behavior difference. The rule must chain out only from the [set characters],
411 # not from the preceding $RI or $CM, which it would be able to do if the set were optional.
412
413 # LB30b Do not break between an emoji base (or potential emoji) and an emoji modifier.
414 $EB $CM* $EM;
415 $ExtPictUnassigned $CM* $EM;
416
417 # LB 31 Break everywhere else.
418 # Match a single code point if no other rule applies.
419 .;