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