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