]> git.saurik.com Git - apple/icu.git/blob - icuSources/data/brkitr/rules/line_normal_cj.txt
ICU-64243.0.1.tar.gz
[apple/icu.git] / icuSources / data / brkitr / rules / line_normal_cj.txt
1 # Copyright (C) 2016 and later: Unicode, Inc. and others.
2 # License & terms of use: http://www.unicode.org/copyright.html
3 # Copyright (c) 2002-2016 International Business Machines Corporation and
4 # others. All Rights Reserved.
5 #
6 # file: line_normal_cj.txt
7 #
8 # Line Breaking Rules
9 # Implement default line breaking as defined by
10 # Unicode Standard Annex #14 Revision 42 for Unicode 12.0
11 # http://www.unicode.org/reports/tr14/, with the following modification:
12 #
13 # Boundaries between hyphens and following letters are suppressed when
14 # there is a boundary preceding the hyphen. See rule 20.9
15 #
16 # This tailors the line break behavior to correspond to CSS
17 # line-break=normal (BCP47 -u-lb-normal) as defined for Chinese & Japanese.
18 # It sets characters of class CJ to behave like ID.
19 # In addition, it allows breaks:
20 # * before hyphens 2010 & 2013 (both BA) and 301C, 30A0 (both NS)
21 # It allows breaking before 201C and after 201D, for zh_Hans, zh_Hant, and ja.
22
23 #
24 # Character Classes defined by TR 14.
25 #
26
27 !!chain;
28 !!quoted_literals_only;
29
30 $AI = [:LineBreak = Ambiguous:];
31 $AL = [:LineBreak = Alphabetic:];
32 $BAX = [\u2010 \u2013];
33 $BA = [[:LineBreak = Break_After:] - $BAX];
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 # CSS Normal tailoring: CJ resolves to ID
53 $ID = [[:LineBreak = Ideographic:] $CJ];
54 $IN = [:LineBreak = Inseperable:];
55 $IS = [:LineBreak = Infix_Numeric:];
56 $JL = [:LineBreak = JL:];
57 $JV = [:LineBreak = JV:];
58 $JT = [:LineBreak = JT:];
59 $LF = [:LineBreak = Line_Feed:];
60 $NL = [:LineBreak = Next_Line:];
61 $NSX = [\u301C \u30A0];
62 $NS = [[:LineBreak = Nonstarter:] - $NSX];
63 $NU = [:LineBreak = Numeric:];
64 $OP = [[:LineBreak = Open_Punctuation:] \u201c];
65 $PO = [:LineBreak = Postfix_Numeric:];
66 $PR = [:LineBreak = Prefix_Numeric:];
67 $QU = [[:LineBreak = Quotation:] - [\u201c\u201d]];
68 $RI = [:LineBreak = Regional_Indicator:];
69 $SA = [:LineBreak = Complex_Context:];
70 $SG = [:LineBreak = Surrogate:];
71 $SP = [:LineBreak = Space:];
72 $SY = [:LineBreak = Break_Symbols:];
73 $WJ = [:LineBreak = Word_Joiner:];
74 $XX = [:LineBreak = Unknown:];
75 $ZW = [:LineBreak = ZWSpace:];
76 $ZWJ = [:LineBreak = ZWJ:];
77
78 # By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly
79 # list it in the numerous rules that use CM.
80 # By LB1, SA characters with general categor of Mn or Mc also resolve to CM.
81
82 $CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]];
83 $CMX = [[$CM] - [$ZWJ]];
84
85 # Dictionary character set, for triggering language-based break engines. Currently
86 # limited to LineBreak=Complex_Context (SA).
87
88 $dictionary = [$SA];
89
90 #
91 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
92 # SA (Dictionary chars, excluding Mn and Mc)
93 # SG (Unpaired Surrogates)
94 # XX (Unknown, unassigned)
95 # as $AL (Alphabetic)
96 #
97 $ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]];
98
99
100 ## -------------------------------------------------
101
102 #
103 # CAN_CM is the set of characters that may combine with CM combining chars.
104 # Note that Linebreak UAX 14's concept of a combining char and the rules
105 # for what they can combine with are _very_ different from the rest of Unicode.
106 #
107 # Note that $CM itself is left out of this set. If CM is needed as a base
108 # it must be listed separately in the rule.
109 #
110 $CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs
111 $CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs
112
113 #
114 # AL_FOLLOW set of chars that can unconditionally follow an AL
115 # Needed in rules where stand-alone $CM s are treated as AL.
116 #
117 $AL_FOLLOW = [$BK $CR $LF $NL $ZW $SP $CL $CP $EX $HL $IS $SY $WJ $GL $OP $QU $BA $HY $NS $IN $NU $PR $PO $ALPlus];
118
119
120 #
121 # Rule LB 4, 5 Mandatory (Hard) breaks.
122 #
123 $LB4Breaks = [$BK $CR $LF $NL];
124 $LB4NonBreaks = [^$BK $CR $LF $NL $CM];
125 $CR $LF {100};
126
127 #
128 # LB 6 Do not break before hard line breaks.
129 #
130 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
131 $CAN_CM $CM* $LB4Breaks {100};
132 ^$CM+ $LB4Breaks {100};
133
134 # LB 7 x SP
135 # x ZW
136 $LB4NonBreaks [$SP $ZW];
137 $CAN_CM $CM* [$SP $ZW];
138 ^$CM+ [$SP $ZW];
139
140 #
141 # LB 8 Break after zero width space
142 # ZW SP* รท
143 #
144 $LB8Breaks = [$LB4Breaks $ZW];
145 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
146 $ZW $SP* / [^$SP $ZW $LB4Breaks];
147
148 # LB 8a ZWJ x Do not break Emoji ZWJ sequences.
149 #
150 $ZWJ [^$CM];
151
152 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
153 # $CM not covered by the above needs to behave like $AL
154 # See definition of $CAN_CM.
155
156 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
157 ^$CM+;
158
159 #
160 # LB 11 Do not break before or after WORD JOINER & related characters.
161 #
162 $CAN_CM $CM* $WJ;
163 $LB8NonBreaks $WJ;
164 ^$CM+ $WJ;
165
166 $WJ $CM* .;
167
168 #
169 # LB 12 Do not break after NBSP and related characters.
170 # GL x
171 #
172 $GL $CM* .;
173
174 #
175 # LB 12a Do not break before NBSP and related characters ...
176 # [^SP BA HY] x GL
177 #
178 [[$LB8NonBreaks] - [$SP $BA $BAX $HY]] $CM* $GL;
179 ^$CM+ $GL;
180
181
182
183
184 # LB 13 Don't break before ']' or '!' or or '/', even after spaces.
185 #
186 $LB8NonBreaks $CL;
187 $CAN_CM $CM* $CL;
188 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
189
190 $LB8NonBreaks $CP;
191 $CAN_CM $CM* $CP;
192 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
193
194 $LB8NonBreaks $EX;
195 $CAN_CM $CM* $EX;
196 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
197
198 $LB8NonBreaks $SY;
199 $CAN_CM $CM* $SY;
200 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
201
202
203 #
204 # LB 14 Do not break after OP, even after spaces
205 # Note subtle interaction with "SP IS /" rules in LB14a.
206 # This rule consumes the SP, chaining happens on the IS, effectivley overriding the SP IS rules,
207 # which is the desired behavior.
208 #
209 $OP $CM* $SP* .;
210
211 $OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
212 # by rule 8, CM following a SP is stand-alone.
213
214
215 # LB 14a Force a break before start of a number with a leading decimal pt, e.g. " .23"
216 # Note: would be simpler to express as "$SP / $IS $CM* $NU;", but ICU rules have limitations.
217 # See issue ICU-20303
218
219
220 $CanFollowIS = [$BK $CR $LF $NL $SP $ZW $WJ $GL $CL $CP $EX $IS $SY $QU $BA $HY $NS $ALPlus $HL];
221 $SP $IS / [^ $CanFollowIS $NU $CM];
222 $SP $IS $CM* $CMX / [^ $CanFollowIS $NU $CM];
223
224 #
225 # LB 14b Do not break before numeric separators (IS), even after spaces.
226
227 [$LB8NonBreaks - $SP] $IS;
228 $SP $IS $CM* [$CanFollowIS {eof}];
229 $SP $IS $CM* $ZWJ [^$CM $NU];
230
231 $CAN_CM $CM* $IS;
232 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
233
234
235 # LB 15
236 $QU $CM* $SP* $OP;
237
238 # LB 16
239 # Do not break between closing punctuation and $NS, even with intervening spaces
240 # But DO allow a break between closing punctuation and $NSX, don't include it here
241 ($CL | $CP) $CM* $SP* $NS;
242
243 # LB 17
244 $B2 $CM* $SP* $B2;
245
246 #
247 # LB 18 Break after spaces.
248 #
249 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
250 $LB18Breaks = [$LB8Breaks $SP];
251
252
253 # LB 19
254 # x QU
255 $LB18NonBreaks $CM* $QU;
256 ^$CM+ $QU;
257
258 # QU x
259 $QU $CM* .;
260
261 # LB 20
262 # <break> $CB
263 # $CB <break>
264 #
265 $LB20NonBreaks = [$LB18NonBreaks - $CB];
266
267 # LB 20.09 Don't break between Hyphens and Letters when there is a break preceding the hyphen.
268 # Originally added as a Finnish tailoring, now promoted to default ICU behavior.
269 # Note: this is not default UAX-14 behaviour. See issue ICU-8151.
270 #
271 ^($HY | $HH) $CM* $ALPlus;
272
273 # LB 21 x (BA | HY | NS)
274 # BB x
275 #
276 # DO allow breaks here before $BAX and $NSX, so don't include them
277 $LB20NonBreaks $CM* ($BA | $HY | $NS);
278
279
280 ^$CM+ ($BA | $HY | $NS);
281
282 $BB $CM* [^$CB]; # $BB x
283 $BB $CM* $LB20NonBreaks;
284
285 # LB 21a Don't break after Hebrew + Hyphen
286 # HL (HY | BA) x
287 #
288 $HL $CM* ($HY | $BA | $BAX) $CM* [^$CB]?;
289
290 # LB 21b (forward) Don't break between SY and HL
291 # (break between HL and SY already disallowed by LB 13 above)
292 $SY $CM* $HL;
293
294 # LB 22
295 ($ALPlus | $HL) $CM* $IN;
296 ^$CM+ $IN; # by rule 10, any otherwise unattached CM behaves as AL
297 $EX $CM* $IN;
298 ($ID | $EB | $EM) $CM* $IN;
299 $IN $CM* $IN;
300 $NU $CM* $IN;
301
302
303 # $LB 23
304 #
305 ($ALPlus | $HL) $CM* $NU;
306 ^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL
307 $NU $CM* ($ALPlus | $HL);
308
309 # LB 23a
310 #
311 $PR $CM* ($ID | $EB | $EM);
312 ($ID | $EB | $EM) $CM* $PO;
313
314
315 #
316 # LB 24
317 #
318 ($PR | $PO) $CM* ($ALPlus | $HL);
319 ($ALPlus | $HL) $CM* ($PR | $PO);
320 ^$CM+ ($PR | $PO); # Rule 10, any otherwise unattached CM behaves as AL
321
322 #
323 # LB 25 Numbers.
324 #
325 (($PR | $PO) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))*
326 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?;
327
328 # LB 26 Do not break a Korean syllable
329 #
330 $JL $CM* ($JL | $JV | $H2 | $H3);
331 ($JV | $H2) $CM* ($JV | $JT);
332 ($JT | $H3) $CM* $JT;
333
334 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
335 ($JL | $JV | $JT | $H2 | $H3) $CM* $IN;
336 ($JL | $JV | $JT | $H2 | $H3) $CM* $PO;
337 $PR $CM* ($JL | $JV | $JT | $H2 | $H3);
338
339
340 # LB 28 Do not break between alphabetics
341 #
342 ($ALPlus | $HL) $CM* ($ALPlus | $HL);
343 ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL
344
345 # LB 29
346 $IS $CM* ($ALPlus | $HL);
347
348 # LB 30
349 ($ALPlus | $HL | $NU) $CM* $OP;
350 ^$CM+ $OP; # The $CM+ is from rule 10, an unattached CM is treated as AL.
351 $CP $CM* ($ALPlus | $HL | $NU);
352
353 # LB 30a Do not break between regional indicators. Break after pairs of them.
354 # Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM.
355 $RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
356 $RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
357 $RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $ZWJ {eof}];
358 # note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?'
359 # because of the chain-out behavior difference. The rule must chain out only from the [set characters],
360 # not from the preceding $RI or $CM, which it would be able to do if the set were optional.
361
362 # LB 30b Do not break between an Emoji Base and an Emoji Modifier
363 $EB $CM* $EM;
364
365 # LB 31 Break everywhere else.
366 # Match a single code point if no other rule applies.
367 .;