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