]>
Commit | Line | Data |
---|---|---|
0f5d89e8 | 1 | # Copyright (C) 2016 and later: Unicode, Inc. and others. |
f3c0d7a5 | 2 | # License & terms of use: http://www.unicode.org/copyright.html |
2ca993e8 | 3 | # Copyright (c) 2002-2016 International Business Machines Corporation and |
46f4442e A |
4 | # others. All Rights Reserved. |
5 | # | |
6 | # file: line.txt | |
7 | # | |
8 | # Line Breaking Rules | |
2ca993e8 | 9 | # Implement default line breaking as defined by |
3d1f044b A |
10 | # Unicode Standard Annex #14 Revision 42 for Unicode 12.0 |
11 | # http://www.unicode.org/reports/tr14/, with the following modification: | |
729e4ab9 | 12 | # |
3d1f044b A |
13 | # Boundaries between hyphens and following letters are suppressed when |
14 | # there is a boundary preceding the hyphen. See rule 20.9 | |
08b89b0a A |
15 | # |
16 | # This corresponds to CSS line-break=strict (BCP47 -u-lb-strict). | |
17 | # It sets characters of class CJ to behave like NS. | |
46f4442e A |
18 | |
19 | # | |
20 | # Character Classes defined by TR 14. | |
21 | # | |
22 | ||
23 | !!chain; | |
0f5d89e8 | 24 | !!quoted_literals_only; |
46f4442e | 25 | |
f3c0d7a5 A |
26 | $AI = [:LineBreak = Ambiguous:]; |
27 | $AL = [:LineBreak = Alphabetic:]; | |
46f4442e | 28 | $BA = [:LineBreak = Break_After:]; |
3d1f044b | 29 | $HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA. |
46f4442e A |
30 | $BB = [:LineBreak = Break_Before:]; |
31 | $BK = [:LineBreak = Mandatory_Break:]; | |
32 | $B2 = [:LineBreak = Break_Both:]; | |
33 | $CB = [:LineBreak = Contingent_Break:]; | |
4388f060 | 34 | $CJ = [:LineBreak = Conditional_Japanese_Starter:]; |
46f4442e | 35 | $CL = [:LineBreak = Close_Punctuation:]; |
f3c0d7a5 | 36 | # $CM = [:LineBreak = Combining_Mark:]; |
729e4ab9 | 37 | $CP = [:LineBreak = Close_Parenthesis:]; |
46f4442e | 38 | $CR = [:LineBreak = Carriage_Return:]; |
3d1f044b | 39 | $EB = [:LineBreak = EB:]; |
f3c0d7a5 | 40 | $EM = [:LineBreak = EM:]; |
46f4442e A |
41 | $EX = [:LineBreak = Exclamation:]; |
42 | $GL = [:LineBreak = Glue:]; | |
4388f060 | 43 | $HL = [:LineBreak = Hebrew_Letter:]; |
46f4442e A |
44 | $HY = [:LineBreak = Hyphen:]; |
45 | $H2 = [:LineBreak = H2:]; | |
46 | $H3 = [:LineBreak = H3:]; | |
f3c0d7a5 | 47 | $ID = [:LineBreak = Ideographic:]; |
46f4442e A |
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:]; | |
f3c0d7a5 | 55 | # NS includes CJ for CSS strict line breaking. |
4388f060 | 56 | $NS = [[:LineBreak = Nonstarter:] $CJ]; |
46f4442e A |
57 | $NU = [:LineBreak = Numeric:]; |
58 | $OP = [:LineBreak = Open_Punctuation:]; | |
59 | $PO = [:LineBreak = Postfix_Numeric:]; | |
60 | $PR = [:LineBreak = Prefix_Numeric:]; | |
61 | $QU = [:LineBreak = Quotation:]; | |
51004dcb | 62 | $RI = [:LineBreak = Regional_Indicator:]; |
46f4442e A |
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:]; | |
f3c0d7a5 A |
70 | $ZWJ = [:LineBreak = ZWJ:]; |
71 | ||
0f5d89e8 A |
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:]; | |
f3c0d7a5 A |
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:]]]]; | |
3d1f044b | 82 | $CMX = [[$CM] - [$ZWJ]]; |
08b89b0a | 83 | |
46f4442e | 84 | # Dictionary character set, for triggering language-based break engines. Currently |
f3c0d7a5 | 85 | # limited to LineBreak=Complex_Context (SA). |
46f4442e | 86 | |
f3c0d7a5 | 87 | $dictionary = [$SA]; |
46f4442e A |
88 | |
89 | # | |
90 | # Rule LB1. By default, treat AI (characters with ambiguous east Asian width), | |
f3c0d7a5 | 91 | # SA (Dictionary chars, excluding Mn and Mc) |
46f4442e A |
92 | # SG (Unpaired Surrogates) |
93 | # XX (Unknown, unassigned) | |
94 | # as $AL (Alphabetic) | |
95 | # | |
f3c0d7a5 A |
96 | $ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]]; |
97 | ||
46f4442e A |
98 | |
99 | ## ------------------------------------------------- | |
100 | ||
46f4442e A |
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. | |
46f4442e | 115 | # |
f3c0d7a5 | 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]; |
46f4442e A |
117 | |
118 | ||
119 | # | |
120 | # Rule LB 4, 5 Mandatory (Hard) breaks. | |
121 | # | |
122 | $LB4Breaks = [$BK $CR $LF $NL]; | |
2ca993e8 | 123 | $LB4NonBreaks = [^$BK $CR $LF $NL $CM]; |
46f4442e A |
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}; | |
2ca993e8 | 131 | ^$CM+ $LB4Breaks {100}; |
46f4442e A |
132 | |
133 | # LB 7 x SP | |
134 | # x ZW | |
135 | $LB4NonBreaks [$SP $ZW]; | |
136 | $CAN_CM $CM* [$SP $ZW]; | |
2ca993e8 | 137 | ^$CM+ [$SP $ZW]; |
46f4442e A |
138 | |
139 | # | |
140 | # LB 8 Break after zero width space | |
3d1f044b | 141 | # ZW SP* ÷ |
46f4442e A |
142 | # |
143 | $LB8Breaks = [$LB4Breaks $ZW]; | |
144 | $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]]; | |
3d1f044b | 145 | $ZW $SP* / [^$SP $ZW $LB4Breaks]; |
46f4442e | 146 | |
0f5d89e8 | 147 | # LB 8a ZWJ x Do not break Emoji ZWJ sequences. |
2ca993e8 | 148 | # |
0f5d89e8 | 149 | $ZWJ [^$CM]; |
46f4442e | 150 | |
2ca993e8 A |
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 | |
46f4442e A |
153 | # See definition of $CAN_CM. |
154 | ||
155 | $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules. | |
2ca993e8 | 156 | ^$CM+; |
46f4442e A |
157 | |
158 | # | |
159 | # LB 11 Do not break before or after WORD JOINER & related characters. | |
160 | # | |
f3c0d7a5 A |
161 | $CAN_CM $CM* $WJ; |
162 | $LB8NonBreaks $WJ; | |
163 | ^$CM+ $WJ; | |
46f4442e | 164 | |
f3c0d7a5 | 165 | $WJ $CM* .; |
46f4442e A |
166 | |
167 | # | |
168 | # LB 12 Do not break after NBSP and related characters. | |
169 | # GL x | |
170 | # | |
f3c0d7a5 | 171 | $GL $CM* .; |
2ca993e8 | 172 | |
46f4442e A |
173 | # |
174 | # LB 12a Do not break before NBSP and related characters ... | |
175 | # [^SP BA HY] x GL | |
176 | # | |
f3c0d7a5 A |
177 | [[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GL; |
178 | ^$CM+ $GL; | |
46f4442e A |
179 | |
180 | ||
181 | ||
3d1f044b A |
182 | |
183 | # LB 13 Don't break before ']' or '!' or or '/', even after spaces. | |
46f4442e A |
184 | # |
185 | $LB8NonBreaks $CL; | |
186 | $CAN_CM $CM* $CL; | |
2ca993e8 | 187 | ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL |
46f4442e | 188 | |
729e4ab9 A |
189 | $LB8NonBreaks $CP; |
190 | $CAN_CM $CM* $CP; | |
2ca993e8 | 191 | ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL |
729e4ab9 | 192 | |
46f4442e A |
193 | $LB8NonBreaks $EX; |
194 | $CAN_CM $CM* $EX; | |
2ca993e8 | 195 | ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL |
46f4442e | 196 | |
46f4442e A |
197 | $LB8NonBreaks $SY; |
198 | $CAN_CM $CM* $SY; | |
2ca993e8 | 199 | ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL |
46f4442e A |
200 | |
201 | ||
202 | # | |
203 | # LB 14 Do not break after OP, even after spaces | |
3d1f044b A |
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. | |
46f4442e | 207 | # |
f3c0d7a5 | 208 | $OP $CM* $SP* .; |
46f4442e | 209 | |
f3c0d7a5 A |
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. | |
46f4442e | 212 | |
3d1f044b A |
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 | ||
46f4442e | 234 | # LB 15 |
f3c0d7a5 | 235 | $QU $CM* $SP* $OP; |
46f4442e A |
236 | |
237 | # LB 16 | |
f3c0d7a5 | 238 | ($CL | $CP) $CM* $SP* $NS; |
46f4442e A |
239 | |
240 | # LB 17 | |
f3c0d7a5 | 241 | $B2 $CM* $SP* $B2; |
46f4442e A |
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 | |
f3c0d7a5 A |
252 | $LB18NonBreaks $CM* $QU; |
253 | ^$CM+ $QU; | |
46f4442e A |
254 | |
255 | # QU x | |
f3c0d7a5 | 256 | $QU $CM* .; |
46f4442e | 257 | |
46f4442e A |
258 | # LB 20 |
259 | # <break> $CB | |
260 | # $CB <break> | |
3d1f044b | 261 | # |
46f4442e A |
262 | $LB20NonBreaks = [$LB18NonBreaks - $CB]; |
263 | ||
3d1f044b A |
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 | ||
46f4442e A |
270 | # LB 21 x (BA | HY | NS) |
271 | # BB x | |
272 | # | |
f3c0d7a5 | 273 | $LB20NonBreaks $CM* ($BA | $HY | $NS); |
3d1f044b A |
274 | |
275 | ||
f3c0d7a5 | 276 | ^$CM+ ($BA | $HY | $NS); |
46f4442e | 277 | |
f3c0d7a5 A |
278 | $BB $CM* [^$CB]; # $BB x |
279 | $BB $CM* $LB20NonBreaks; | |
46f4442e | 280 | |
4388f060 A |
281 | # LB 21a Don't break after Hebrew + Hyphen |
282 | # HL (HY | BA) x | |
2ca993e8 | 283 | # |
f3c0d7a5 | 284 | $HL $CM* ($HY | $BA) $CM* [^$CB]?; |
4388f060 | 285 | |
51004dcb A |
286 | # LB 21b (forward) Don't break between SY and HL |
287 | # (break between HL and SY already disallowed by LB 13 above) | |
f3c0d7a5 | 288 | $SY $CM* $HL; |
51004dcb | 289 | |
46f4442e | 290 | # LB 22 |
f3c0d7a5 A |
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; | |
46f4442e A |
297 | |
298 | ||
299 | # $LB 23 | |
f3c0d7a5 A |
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 | ||
46f4442e A |
310 | |
311 | # | |
312 | # LB 24 | |
313 | # | |
f3c0d7a5 A |
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 | |
46f4442e A |
317 | |
318 | # | |
319 | # LB 25 Numbers. | |
320 | # | |
3d1f044b | 321 | (($PR | $PO) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))* |
f3c0d7a5 | 322 | ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?; |
46f4442e A |
323 | |
324 | # LB 26 Do not break a Korean syllable | |
325 | # | |
f3c0d7a5 A |
326 | $JL $CM* ($JL | $JV | $H2 | $H3); |
327 | ($JV | $H2) $CM* ($JV | $JT); | |
328 | ($JT | $H3) $CM* $JT; | |
46f4442e A |
329 | |
330 | # LB 27 Treat korean Syllable Block the same as ID (don't break it) | |
f3c0d7a5 A |
331 | ($JL | $JV | $JT | $H2 | $H3) $CM* $IN; |
332 | ($JL | $JV | $JT | $H2 | $H3) $CM* $PO; | |
333 | $PR $CM* ($JL | $JV | $JT | $H2 | $H3); | |
46f4442e A |
334 | |
335 | ||
336 | # LB 28 Do not break between alphabetics | |
337 | # | |
f3c0d7a5 A |
338 | ($ALPlus | $HL) $CM* ($ALPlus | $HL); |
339 | ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL | |
46f4442e A |
340 | |
341 | # LB 29 | |
f3c0d7a5 | 342 | $IS $CM* ($ALPlus | $HL); |
46f4442e | 343 | |
729e4ab9 | 344 | # LB 30 |
f3c0d7a5 A |
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); | |
729e4ab9 | 348 | |
2ca993e8 | 349 | # LB 30a Do not break between regional indicators. Break after pairs of them. |
0f5d89e8 A |
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. | |
2ca993e8 A |
357 | |
358 | # LB 30b Do not break between an Emoji Base and an Emoji Modifier | |
359 | $EB $CM* $EM; | |
08b89b0a | 360 | |
0f5d89e8 A |
361 | # LB 31 Break everywhere else. |
362 | # Match a single code point if no other rule applies. | |
363 | .; |