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