]> git.saurik.com Git - apple/icu.git/blob - icuSources/data/brkitr/rules/line_loose_cj.txt
ICU-66108.tar.gz
[apple/icu.git] / icuSources / data / brkitr / rules / line_loose_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_loose_cj.txt
7 #
8 # Line Breaking Rules
9 # Implement default line breaking as defined by
10 # Unicode Standard Annex #14 Revision 44 for Unicode 13.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=loose (BCP47 -u-lb-loose) 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 # * before iteration marks 3005, 303B, 309D, 309E, 30FD, 30FE (all NS)
22 # * between characters of LineBreak class IN such as 2026
23 # * before some centered punct 203C, 2047, 2048, 2049, 30FB, FF1A, FF1B,
24 # FF65 (all NS) and FF01, FF1F (both EX).
25 # * before suffix characters with LineBreak class PO and EastAsianWidth A,F,W;
26 # this includes: 00B0 2030 2032 2033 2035 2103 2109 FE6A FF05 FFE0
27 # * after prefix characters with LineBreak class PR and EastAsianWidth A,F,W;
28 # this includes: 00A4 00B1 20AC 2116 FE69 FF04 FFE1 FFE5 FFE6
29 # It allows breaking before 201C and after 201D, for zh_Hans, zh_Hant, and ja.
30
31
32 #
33 # Character Classes defined by TR 14.
34 #
35
36 !!chain;
37 !!quoted_literals_only;
38
39 $AI = [:LineBreak = Ambiguous:];
40 $AL = [:LineBreak = Alphabetic:];
41 $BAX = [\u2010 \u2013];
42 $BA = [[:LineBreak = Break_After:] - $BAX];
43 $HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA.
44 $BB = [:LineBreak = Break_Before:];
45 $BK = [:LineBreak = Mandatory_Break:];
46 $B2 = [:LineBreak = Break_Both:];
47 $CB = [:LineBreak = Contingent_Break:];
48 $CJ = [:LineBreak = Conditional_Japanese_Starter:];
49 $CL = [[:LineBreak = Close_Punctuation:] \u201d];
50 # $CM = [:LineBreak = Combining_Mark:];
51 $CP = [:LineBreak = Close_Parenthesis:];
52 $CR = [:LineBreak = Carriage_Return:];
53 $EB = [:LineBreak = EB:];
54 $EM = [:LineBreak = EM:];
55 $EXX = [\uFF01 \uFF1F];
56 $EX = [[:LineBreak = Exclamation:] - $EXX];
57 $GL = [:LineBreak = Glue:];
58 $HL = [:LineBreak = Hebrew_Letter:];
59 $HY = [:LineBreak = Hyphen:];
60 $H2 = [:LineBreak = H2:];
61 $H3 = [:LineBreak = H3:];
62 # CSS Loose tailoring: CJ resolves to ID
63 $ID = [[:LineBreak = Ideographic:] $CJ];
64 $IN = [:LineBreak = Inseperable:];
65 $IS = [:LineBreak = Infix_Numeric:];
66 $JL = [:LineBreak = JL:];
67 $JV = [:LineBreak = JV:];
68 $JT = [:LineBreak = JT:];
69 $LF = [:LineBreak = Line_Feed:];
70 $NL = [:LineBreak = Next_Line:];
71 $NSX = [\u301C \u30A0 \u3005 \u303B \u309D \u309E \u30FD \u30FE \u203C \u2047 \u2048 \u2049 \u30FB \uFF1A \uFF1B \uFF65];
72 $NS = [[:LineBreak = Nonstarter:] - $NSX];
73 $NU = [:LineBreak = Numeric:];
74 $OP = [[:LineBreak = Open_Punctuation:] \u201c];
75 $POX = [\u00B0 \u2030 \u2032 \u2033 \u2035 \u2103 \u2109 \uFE6A \uFF05 \uFFE0];
76 $PO = [[:LineBreak = Postfix_Numeric:] - $POX];
77 $PRX = [\u00A4 \u00B1 \u20AC \u2116 \uFE69 \uFF04 \uFFE1 \uFFE5 \uFFE6];
78 $PR = [[:LineBreak = Prefix_Numeric:] - $PRX];
79 $QU = [[:LineBreak = Quotation:] - [\u201c\u201d]];
80 $RI = [:LineBreak = Regional_Indicator:];
81 $SA = [:LineBreak = Complex_Context:];
82 $SG = [:LineBreak = Surrogate:];
83 $SP = [:LineBreak = Space:];
84 $SY = [:LineBreak = Break_Symbols:];
85 $WJ = [:LineBreak = Word_Joiner:];
86 $XX = [:LineBreak = Unknown:];
87 $ZW = [:LineBreak = ZWSpace:];
88 $ZWJ = [:LineBreak = ZWJ:];
89
90 # OP30 and CP30 are variants of OP and CP that appear in-line in rule LB30 from UAX 14,
91 # without a formal name. Because ICU rules require multiple uses of the expressions,
92 # give them a single definition with a name
93
94 $OP30 = [$OP - [\p{ea=F}\p{ea=W}\p{ea=H}]];
95 $CP30 = [$CP - [\p{ea=F}\p{ea=W}\p{ea=H}]];
96
97 # By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly
98 # list it in the numerous rules that use CM.
99 # By LB1, SA characters with general categor of Mn or Mc also resolve to CM.
100
101 $CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]];
102 $CMX = [[$CM] - [$ZWJ]];
103
104 # Dictionary character set, for triggering language-based break engines. Currently
105 # limited to LineBreak=Complex_Context (SA).
106
107 $dictionary = [$SA];
108
109 #
110 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
111 # SA (Dictionary chars, excluding Mn and Mc)
112 # SG (Unpaired Surrogates)
113 # XX (Unknown, unassigned)
114 # as $AL (Alphabetic)
115 #
116 $ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]];
117
118
119 ## -------------------------------------------------
120
121 #
122 # CAN_CM is the set of characters that may combine with CM combining chars.
123 # Note that Linebreak UAX 14's concept of a combining char and the rules
124 # for what they can combine with are _very_ different from the rest of Unicode.
125 #
126 # Note that $CM itself is left out of this set. If CM is needed as a base
127 # it must be listed separately in the rule.
128 #
129 $CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs
130 $CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs
131
132 #
133 # AL_FOLLOW set of chars that can unconditionally follow an AL
134 # Needed in rules where stand-alone $CM s are treated as AL.
135 #
136 $AL_FOLLOW = [$BK $CR $LF $NL $ZW $SP $CL $CP $EX $HL $IS $SY $WJ $GL $OP30 $QU $BA $HY $NS $IN $NU $PR $PO $POX $ALPlus];
137
138
139 #
140 # Rule LB 4, 5 Mandatory (Hard) breaks.
141 #
142 $LB4Breaks = [$BK $CR $LF $NL];
143 $LB4NonBreaks = [^$BK $CR $LF $NL $CM];
144 $CR $LF {100};
145
146 #
147 # LB 6 Do not break before hard line breaks.
148 #
149 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
150 $CAN_CM $CM* $LB4Breaks {100};
151 ^$CM+ $LB4Breaks {100};
152
153 # LB 7 x SP
154 # x ZW
155 $LB4NonBreaks [$SP $ZW];
156 $CAN_CM $CM* [$SP $ZW];
157 ^$CM+ [$SP $ZW];
158
159 #
160 # LB 8 Break after zero width space
161 # ZW SP* รท
162 #
163 $LB8Breaks = [$LB4Breaks $ZW];
164 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
165 $ZW $SP* / [^$SP $ZW $LB4Breaks];
166
167 # LB 8a ZWJ x Do not break Emoji ZWJ sequences.
168 #
169 $ZWJ [^$CM];
170
171 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
172 # $CM not covered by the above needs to behave like $AL
173 # See definition of $CAN_CM.
174
175 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
176 ^$CM+;
177
178 #
179 # LB 11 Do not break before or after WORD JOINER & related characters.
180 #
181 $CAN_CM $CM* $WJ;
182 $LB8NonBreaks $WJ;
183 ^$CM+ $WJ;
184
185 $WJ $CM* .;
186
187 #
188 # LB 12 Do not break after NBSP and related characters.
189 # GL x
190 #
191 $GL $CM* .;
192
193 #
194 # LB 12a Do not break before NBSP and related characters ...
195 # [^SP BA HY] x GL
196 #
197 [[$LB8NonBreaks] - [$SP $BA $BAX $HY]] $CM* $GL;
198 ^$CM+ $GL;
199
200
201
202 # LB 13 Don't break before ']' or '!' or or '/', even after spaces.
203 #
204 # Do not include $EXX here
205 $LB8NonBreaks $CL;
206 $CAN_CM $CM* $CL;
207 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
208
209 $LB8NonBreaks $CP;
210 $CAN_CM $CM* $CP;
211 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
212
213 $LB8NonBreaks $EX;
214 $CAN_CM $CM* $EX;
215 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
216
217 $LB8NonBreaks $SY;
218 $CAN_CM $CM* $SY;
219 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
220
221
222 #
223 # LB 14 Do not break after OP, even after spaces
224 # Note subtle interaction with "SP IS /" rules in LB14a.
225 # This rule consumes the SP, chaining happens on the IS, effectivley overriding the SP IS rules,
226 # which is the desired behavior.
227 #
228 $OP $CM* $SP* .;
229
230 $OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
231 # by rule 8, CM following a SP is stand-alone.
232
233
234 # LB 14a Force a break before start of a number with a leading decimal pt, e.g. " .23"
235 # Note: would be simpler to express as "$SP / $IS $CM* $NU;", but ICU rules have limitations.
236 # See issue ICU-20303
237
238
239 $CanFollowIS = [$BK $CR $LF $NL $SP $ZW $WJ $GL $CL $CP $EX $IS $SY $QU $BA $HY $NS $ALPlus $HL $IN];
240 $SP $IS / [^ $CanFollowIS $NU $CM];
241 $SP $IS $CM* $CMX / [^ $CanFollowIS $NU $CM];
242
243 #
244 # LB 14b Do not break before numeric separators (IS), even after spaces.
245
246 [$LB8NonBreaks - $SP] $IS;
247 $SP $IS $CM* [$CanFollowIS {eof}];
248 $SP $IS $CM* $ZWJ [^$CM $NU];
249
250 $CAN_CM $CM* $IS;
251 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
252
253
254 # LB 15
255 $QU $CM* $SP* $OP;
256
257 # LB 16
258 # Do not break between closing punctuation and $NS, even with intervening spaces
259 # But DO allow a break between closing punctuation and $NSX, don't include it here
260 ($CL | $CP) $CM* $SP* $NS;
261
262 # LB 17
263 $B2 $CM* $SP* $B2;
264
265 #
266 # LB 18 Break after spaces.
267 #
268 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
269 $LB18Breaks = [$LB8Breaks $SP];
270
271
272 # LB 19
273 # x QU
274 $LB18NonBreaks $CM* $QU;
275 ^$CM+ $QU;
276
277 # QU x
278 $QU $CM* .;
279
280 # LB 20
281 # <break> $CB
282 # $CB <break>
283 #
284 $LB20NonBreaks = [$LB18NonBreaks - $CB];
285
286 # LB 20.09 Don't break between Hyphens and Letters when there is a break preceding the hyphen.
287 # Originally added as a Finnish tailoring, now promoted to default ICU behavior.
288 # Note: this is not default UAX-14 behaviour. See issue ICU-8151.
289 #
290 ^($HY | $HH) $CM* $ALPlus;
291
292 # LB 21 x (BA | HY | NS)
293 # BB x
294 #
295 # DO allow breaks here before $BAX and $NSX, so don't include them
296 $LB20NonBreaks $CM* ($BA | $HY | $NS);
297
298
299 ^$CM+ ($BA | $HY | $NS);
300
301 $BB $CM* [^$CB]; # $BB x
302 $BB $CM* $LB20NonBreaks;
303
304 # LB 21a Don't break after Hebrew + Hyphen
305 # HL (HY | BA) x
306 #
307 $HL $CM* ($HY | $BA | $BAX) $CM* [^$CB]?;
308
309 # LB 21b (forward) Don't break between SY and HL
310 # (break between HL and SY already disallowed by LB 13 above)
311 $SY $CM* $HL;
312
313
314 # LB 22 Do not break before ellipses
315 #
316 [$LB20NonBreaks - $IN] $CM* $IN; # line_loose tailoring
317 ^$CM+ $IN;
318
319
320 # LB 23
321 #
322 ($ALPlus | $HL) $CM* $NU;
323 ^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL
324 $NU $CM* ($ALPlus | $HL);
325
326 # LB 23a
327 # Do not include $POX here
328 #
329 $PR $CM* ($ID | $EB | $EM);
330 ($ID | $EB | $EM) $CM* $PO;
331
332
333 #
334 # LB 24
335 #
336 # Do not include $PRX here
337 ($PR | $PO | $POX) $CM* ($ALPlus | $HL);
338 ($ALPlus | $HL) $CM* ($PR | $PO | $POX); # TODO: should this be ($PR | $PRX | $PO)
339 ^$CM+ ($PR | $PO | $POX); # Rule 10, any otherwise unattached CM behaves as AL
340
341 #
342 # LB 25 Numbers.
343 #
344 # Here do not include $PRX at the beginning or $POX at the end
345 (($PR | $PO | $POX) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))*
346 ($CM* ($CL | $CP))? ($CM* ($PR | $PRX | $PO))?;
347
348 # LB 26 Do not break a Korean syllable
349 #
350 $JL $CM* ($JL | $JV | $H2 | $H3);
351 ($JV | $H2) $CM* ($JV | $JT);
352 ($JT | $H3) $CM* $JT;
353
354 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
355 # Do not include $POX or $PRX here
356 ($JL | $JV | $JT | $H2 | $H3) $CM* $IN;
357 ($JL | $JV | $JT | $H2 | $H3) $CM* $PO;
358 $PR $CM* ($JL | $JV | $JT | $H2 | $H3);
359
360
361 # LB 28 Do not break between alphabetics
362 #
363 ($ALPlus | $HL) $CM* ($ALPlus | $HL);
364 ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL
365
366 # LB 29
367 $IS $CM* ($ALPlus | $HL);
368
369 # LB 30
370 ($ALPlus | $HL | $NU) $CM* $OP30;
371 ^$CM+ $OP30; # The $CM+ is from rule 10, an unattached CM is treated as AL.
372 $CP30 $CM* ($ALPlus | $HL | $NU);
373
374 # LB 30a Do not break between regional indicators. Break after pairs of them.
375 # Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM.
376 $RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $CM]];
377 $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]];
378 $RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $ZWJ {eof}];
379 # note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?'
380 # because of the chain-out behavior difference. The rule must chain out only from the [set characters],
381 # not from the preceding $RI or $CM, which it would be able to do if the set were optional.
382
383 # LB 30b Do not break between an Emoji Base and an Emoji Modifier
384 $EB $CM* $EM;
385
386 # LB 31 Break everywhere else.
387 # Match a single code point if no other rule applies.
388 .;