]>
Commit | Line | Data |
---|---|---|
1 | # Copyright (C) 2016 and later: Unicode, Inc. and others. | |
2 | # License & terms of use: http://www.unicode.org/copyright.html | |
3 | # | |
4 | # Copyright (c) 2002-2016 International Business Machines Corporation and | |
5 | # others. All Rights Reserved. | |
6 | # | |
7 | # file: line_loose.txt | |
8 | # | |
9 | # Line Breaking Rules | |
10 | # Implement default line breaking as defined by | |
11 | # Unicode Standard Annex #14 Revision 40 for Unicode 11.0 | |
12 | # http://www.unicode.org/reports/tr14/ | |
13 | # | |
14 | # tailored as noted in 2nd paragraph below. | |
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 | |
21 | # line-break=loose (BCP47 -u-lb-loose) as defined for languages other than | |
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; | |
33 | !!quoted_literals_only; | |
34 | ||
35 | $AI = [:LineBreak = Ambiguous:]; | |
36 | $AL = [:LineBreak = Alphabetic:]; | |
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:]; | |
44 | # $CM = [:LineBreak = Combining_Mark:]; | |
45 | $CP = [:LineBreak = Close_Parenthesis:]; | |
46 | $CR = [:LineBreak = Carriage_Return:]; | |
47 | $EB = [[:LineBreak = EB:] \U0001F46A-\U0001F46D\U0001F46F\U0001F91D\U0001F93C]; | |
48 | $EM = [:LineBreak = EM:]; | |
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:]; | |
55 | # CSS Loose tailoring: CJ resolves to ID | |
56 | $ID = [[:LineBreak = Ideographic:] $CJ]; | |
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:]; | |
79 | $ZWJ = [:LineBreak = ZWJ:]; | |
80 | ||
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:]]]]; | |
86 | ||
87 | # Dictionary character set, for triggering language-based break engines. Currently | |
88 | # limited to LineBreak=Complex_Context (SA). | |
89 | ||
90 | $dictionary = [$SA]; | |
91 | ||
92 | # | |
93 | # Rule LB1. By default, treat AI (characters with ambiguous east Asian width), | |
94 | # SA (Dictionary chars, excluding Mn and Mc) | |
95 | # SG (Unpaired Surrogates) | |
96 | # XX (Unknown, unassigned) | |
97 | # as $AL (Alphabetic) | |
98 | # | |
99 | $ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]]; | |
100 | ||
101 | ||
102 | ## ------------------------------------------------- | |
103 | ||
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. | |
118 | # | |
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]; | |
120 | ||
121 | ||
122 | # | |
123 | # Rule LB 4, 5 Mandatory (Hard) breaks. | |
124 | # | |
125 | $LB4Breaks = [$BK $CR $LF $NL]; | |
126 | $LB4NonBreaks = [^$BK $CR $LF $NL $CM]; | |
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}; | |
134 | ^$CM+ $LB4Breaks {100}; | |
135 | ||
136 | # LB 7 x SP | |
137 | # x ZW | |
138 | $LB4NonBreaks [$SP $ZW]; | |
139 | $CAN_CM $CM* [$SP $ZW]; | |
140 | ^$CM+ [$SP $ZW]; | |
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 | ||
151 | # LB 8a ZWJ x Do not break Emoji ZWJ sequences. | |
152 | # | |
153 | $ZWJ [^$CM]; | |
154 | ||
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 | |
157 | # See definition of $CAN_CM. | |
158 | ||
159 | $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules. | |
160 | ^$CM+; | |
161 | ||
162 | # | |
163 | # LB 11 Do not break before or after WORD JOINER & related characters. | |
164 | # | |
165 | $CAN_CM $CM* $WJ; | |
166 | $LB8NonBreaks $WJ; | |
167 | ^$CM+ $WJ; | |
168 | ||
169 | $WJ $CM* .; | |
170 | ||
171 | # | |
172 | # LB 12 Do not break after NBSP and related characters. | |
173 | # GL x | |
174 | # | |
175 | $GL $CM* .; | |
176 | ||
177 | # | |
178 | # LB 12a Do not break before NBSP and related characters ... | |
179 | # [^SP BA HY] x GL | |
180 | # | |
181 | [[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GL; | |
182 | ^$CM+ $GL; | |
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; | |
191 | ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL | |
192 | ||
193 | $LB8NonBreaks $CP; | |
194 | $CAN_CM $CM* $CP; | |
195 | ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL | |
196 | ||
197 | $LB8NonBreaks $EX; | |
198 | $CAN_CM $CM* $EX; | |
199 | ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL | |
200 | ||
201 | $LB8NonBreaks $IS; | |
202 | $CAN_CM $CM* $IS; | |
203 | ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL | |
204 | ||
205 | $LB8NonBreaks $SY; | |
206 | $CAN_CM $CM* $SY; | |
207 | ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL | |
208 | ||
209 | ||
210 | # | |
211 | # LB 14 Do not break after OP, even after spaces | |
212 | # | |
213 | $OP $CM* $SP* .; | |
214 | ||
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. | |
217 | ||
218 | # LB 15 | |
219 | $QU $CM* $SP* $OP; | |
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 | |
224 | ($CL | $CP) $CM* $SP* $NS; | |
225 | ||
226 | # LB 17 | |
227 | $B2 $CM* $SP* $B2; | |
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 | |
238 | $LB18NonBreaks $CM* $QU; | |
239 | ^$CM+ $QU; | |
240 | ||
241 | # QU x | |
242 | $QU $CM* .; | |
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 | # | |
254 | # DO allow breaks here before NSX, so don't include it | |
255 | $LB20NonBreaks $CM* ($BA | $HY | $NS); | |
256 | ^$CM+ ($BA | $HY | $NS); | |
257 | ||
258 | $BB $CM* [^$CB]; # $BB x | |
259 | $BB $CM* $LB20NonBreaks; | |
260 | ||
261 | # LB 21a Don't break after Hebrew + Hyphen | |
262 | # HL (HY | BA) x | |
263 | # | |
264 | $HL $CM* ($HY | $BA) $CM* [^$CB]?; | |
265 | ||
266 | # LB 21b (forward) Don't break between SY and HL | |
267 | # (break between HL and SY already disallowed by LB 13 above) | |
268 | $SY $CM* $HL; | |
269 | ||
270 | # LB 22 | |
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; | |
277 | ||
278 | ||
279 | # $LB 23 | |
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 | ||
290 | ||
291 | # | |
292 | # LB 24 | |
293 | # | |
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 | |
297 | ||
298 | # | |
299 | # LB 25 Numbers. | |
300 | # | |
301 | (($PR | $PO) $CM*)? (($OP | $HY) $CM*)? $NU ($CM* ($NU | $SY | $IS))* | |
302 | ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?; | |
303 | ||
304 | # LB 26 Do not break a Korean syllable | |
305 | # | |
306 | $JL $CM* ($JL | $JV | $H2 | $H3); | |
307 | ($JV | $H2) $CM* ($JV | $JT); | |
308 | ($JT | $H3) $CM* $JT; | |
309 | ||
310 | # LB 27 Treat korean Syllable Block the same as ID (don't break it) | |
311 | ($JL | $JV | $JT | $H2 | $H3) $CM* $IN; | |
312 | ($JL | $JV | $JT | $H2 | $H3) $CM* $PO; | |
313 | $PR $CM* ($JL | $JV | $JT | $H2 | $H3); | |
314 | ||
315 | ||
316 | # LB 28 Do not break between alphabetics | |
317 | # | |
318 | ($ALPlus | $HL) $CM* ($ALPlus | $HL); | |
319 | ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL | |
320 | ||
321 | # LB 29 | |
322 | $IS $CM* ($ALPlus | $HL); | |
323 | ||
324 | # LB 30 | |
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); | |
328 | ||
329 | # LB 30a Do not break between regional indicators. Break after pairs of them. | |
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. | |
337 | ||
338 | # LB 30b Do not break between an Emoji Base and an Emoji Modifier | |
339 | $EB $CM* $EM; | |
340 | ||
341 | # LB 31 Break everywhere else. | |
342 | # Match a single code point if no other rule applies. | |
343 | .; |