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