1 # Copyright (C) 2016 and later: Unicode, Inc. and others.
2 # License & terms of use: http://www.unicode.org/copyright.html
3 # Copyright (c) 2002-2016 International Business Machines Corporation and
4 # others. All Rights Reserved.
6 # file: line_loose_cj.txt
9 # Implement default line breaking as defined by
10 # Unicode Standard Annex #14 Revision 40 for Unicode 11.0
11 # http://www.unicode.org/reports/tr14/
13 # tailored as noted in 2nd paragraph below.
15 # TODO: Rule LB 8 remains as it was in Unicode 5.2
16 # This is only because of a limitation of ICU break engine implementation,
17 # not because the older behavior is desirable.
19 # This tailors the line break behavior to correspond to CSS
20 # line-break=loose (BCP47 -u-lb-loose) as defined for Chinese & Japanese.
21 # It sets characters of class CJ to behave like ID.
22 # In addition, it allows breaks:
23 # * before hyphens 2010 & 2013 (both BA) and 301C, 30A0 (both NS)
24 # * before iteration marks 3005, 303B, 309D, 309E, 30FD, 30FE (all NS)
25 # * between characters of LineBreak class IN such as 2026
26 # * before some centered punct 203C, 2047, 2048, 2049, 30FB, FF1A, FF1B,
27 # FF65 (all NS) and FF01, FF1F (both EX).
28 # * before suffix characters with LineBreak class PO and EastAsianWidth A,F,W;
29 # this includes: 00B0 2030 2032 2033 2035 2103 2109 FE6A FF05 FFE0
30 # * after prefix characters with LineBreak class PR and EastAsianWidth A,F,W;
31 # this includes: 00A4 00B1 20AC 2116 FE69 FF04 FFE1 FFE5 FFE6
35 # Character Classes defined by TR 14.
39 !!quoted_literals_only;
41 $AI = [:LineBreak = Ambiguous:];
42 $AL = [:LineBreak = Alphabetic:];
43 $BAX = [\u2010 \u2013];
44 $BA = [[:LineBreak = Break_After:] - $BAX];
45 $BB = [:LineBreak = Break_Before:];
46 $BK = [:LineBreak = Mandatory_Break:];
47 $B2 = [:LineBreak = Break_Both:];
48 $CB = [:LineBreak = Contingent_Break:];
49 $CJ = [:LineBreak = Conditional_Japanese_Starter:];
50 $CL = [:LineBreak = Close_Punctuation:];
51 # $CM = [:LineBreak = Combining_Mark:];
52 $CP = [:LineBreak = Close_Parenthesis:];
53 $CR = [:LineBreak = Carriage_Return:];
54 $EB = [[:LineBreak = EB:] \U0001F46A-\U0001F46D\U0001F46F\U0001F91D\U0001F93C];
55 $EM = [:LineBreak = EM:];
56 $EXX = [\uFF01 \uFF1F];
57 $EX = [[:LineBreak = Exclamation:] - $EXX];
58 $GL = [:LineBreak = Glue:];
59 $HL = [:LineBreak = Hebrew_Letter:];
60 $HY = [:LineBreak = Hyphen:];
61 $H2 = [:LineBreak = H2:];
62 $H3 = [:LineBreak = H3:];
63 # CSS Loose tailoring: CJ resolves to ID
64 $ID = [[:LineBreak = Ideographic:] $CJ];
65 $IN = [:LineBreak = Inseperable:];
66 $IS = [:LineBreak = Infix_Numeric:];
67 $JL = [:LineBreak = JL:];
68 $JV = [:LineBreak = JV:];
69 $JT = [:LineBreak = JT:];
70 $LF = [:LineBreak = Line_Feed:];
71 $NL = [:LineBreak = Next_Line:];
72 $NSX = [\u301C \u30A0 \u3005 \u303B \u309D \u309E \u30FD \u30FE \u203C \u2047 \u2048 \u2049 \u30FB \uFF1A \uFF1B \uFF65];
73 $NS = [[:LineBreak = Nonstarter:] - $NSX];
74 $NU = [:LineBreak = Numeric:];
75 $OP = [:LineBreak = Open_Punctuation:];
76 $POX = [\u00B0 \u2030 \u2032 \u2033 \u2035 \u2103 \u2109 \uFE6A \uFF05 \uFFE0];
77 $PO = [[:LineBreak = Postfix_Numeric:] - $POX];
78 $PRX = [\u00A4 \u00B1 \u20AC \u2116 \uFE69 \uFF04 \uFFE1 \uFFE5 \uFFE6];
79 $PR = [[:LineBreak = Prefix_Numeric:] - $PRX];
80 $QU = [:LineBreak = Quotation:];
81 $RI = [:LineBreak = Regional_Indicator:];
82 $SA = [:LineBreak = Complex_Context:];
83 $SG = [:LineBreak = Surrogate:];
84 $SP = [:LineBreak = Space:];
85 $SY = [:LineBreak = Break_Symbols:];
86 $WJ = [:LineBreak = Word_Joiner:];
87 $XX = [:LineBreak = Unknown:];
88 $ZW = [:LineBreak = ZWSpace:];
89 $ZWJ = [:LineBreak = ZWJ:];
91 # By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly
92 # list it in the numerous rules that use CM.
93 # By LB1, SA characters with general categor of Mn or Mc also resolve to CM.
95 $CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]];
97 # Dictionary character set, for triggering language-based break engines. Currently
98 # limited to LineBreak=Complex_Context (SA).
103 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
104 # SA (Dictionary chars, excluding Mn and Mc)
105 # SG (Unpaired Surrogates)
106 # XX (Unknown, unassigned)
107 # as $AL (Alphabetic)
109 $ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]];
112 ## -------------------------------------------------
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.
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.
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
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.
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];
133 # Rule LB 4, 5 Mandatory (Hard) breaks.
135 $LB4Breaks = [$BK $CR $LF $NL];
136 $LB4NonBreaks = [^$BK $CR $LF $NL $CM];
140 # LB 6 Do not break before hard line breaks.
142 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
143 $CAN_CM $CM* $LB4Breaks {100};
144 ^$CM+ $LB4Breaks {100};
148 $LB4NonBreaks [$SP $ZW];
149 $CAN_CM $CM* [$SP $ZW];
153 # LB 8 Break after zero width space
154 # TODO: ZW SP* <break>
155 # An engine change is required to write the reverse rule for this.
156 # For now, leave the Unicode 5.2 rule, ZW <break>
158 $LB8Breaks = [$LB4Breaks $ZW];
159 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
161 # LB 8a ZWJ x Do not break Emoji ZWJ sequences.
165 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
166 # $CM not covered by the above needs to behave like $AL
167 # See definition of $CAN_CM.
169 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
173 # LB 11 Do not break before or after WORD JOINER & related characters.
182 # LB 12 Do not break after NBSP and related characters.
188 # LB 12a Do not break before NBSP and related characters ...
191 [[$LB8NonBreaks] - [$SP $BA $BAX $HY]] $CM* $GL;
196 # LB 13 Don't break before ']' or '!' or ';' or '/', even after spaces.
198 # Do not include $EXX here
201 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
205 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
209 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
213 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
217 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
221 # LB 14 Do not break after OP, even after spaces
225 $OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
226 # by rule 8, CM following a SP is stand-alone.
232 # Do not break between closing punctuation and $NS, even with intervening spaces
233 # But DO allow a break between closing punctuation and $NSX, don't include it here
234 ($CL | $CP) $CM* $SP* $NS;
240 # LB 18 Break after spaces.
242 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
243 $LB18Breaks = [$LB8Breaks $SP];
248 $LB18NonBreaks $CM* $QU;
259 $LB20NonBreaks = [$LB18NonBreaks - $CB];
261 # LB 21 x (BA | HY | NS)
264 # DO allow breaks here before $BAX and $NSX, so don't include them
265 $LB20NonBreaks $CM* ($BA | $HY | $NS);
266 ^$CM+ ($BA | $HY | $NS);
268 $BB $CM* [^$CB]; # $BB x
269 $BB $CM* $LB20NonBreaks;
271 # LB 21a Don't break after Hebrew + Hyphen
274 $HL $CM* ($HY | $BA | $BAX) $CM* [^$CB]?;
276 # LB 21b (forward) Don't break between SY and HL
277 # (break between HL and SY already disallowed by LB 13 above)
281 ($ALPlus | $HL) $CM* $IN;
282 ^$CM+ $IN; # by rule 10, any otherwise unattached CM behaves as AL
284 ($ID | $EB | $EM) $CM* $IN;
285 # $IN $CM* $IN; # delete this rule for CSS loose
291 ($ALPlus | $HL) $CM* $NU;
292 ^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL
293 $NU $CM* ($ALPlus | $HL);
296 # Do not include $POX here
298 $PR $CM* ($ID | $EB | $EM);
299 ($ID | $EB | $EM) $CM* $PO;
305 # Do not include $PRX here
306 ($PR | $PO | $POX) $CM* ($ALPlus | $HL);
307 ($ALPlus | $HL) $CM* ($PR | $PO | $POX); # TODO: should this be ($PR | $PRX | $PO)
308 ^$CM+ ($PR | $PO | $POX); # Rule 10, any otherwise unattached CM behaves as AL
313 # Here do not include $PRX at the beginning or $POX at the end
314 (($PR | $PO | $POX) $CM*)? (($OP | $HY) $CM*)? $NU ($CM* ($NU | $SY | $IS))*
315 ($CM* ($CL | $CP))? ($CM* ($PR | $PRX | $PO))?;
317 # LB 26 Do not break a Korean syllable
319 $JL $CM* ($JL | $JV | $H2 | $H3);
320 ($JV | $H2) $CM* ($JV | $JT);
321 ($JT | $H3) $CM* $JT;
323 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
324 # Do not include $POX or $PRX here
325 ($JL | $JV | $JT | $H2 | $H3) $CM* $IN;
326 ($JL | $JV | $JT | $H2 | $H3) $CM* $PO;
327 $PR $CM* ($JL | $JV | $JT | $H2 | $H3);
330 # LB 28 Do not break between alphabetics
332 ($ALPlus | $HL) $CM* ($ALPlus | $HL);
333 ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL
336 $IS $CM* ($ALPlus | $HL);
339 ($ALPlus | $HL | $NU) $CM* $OP;
340 ^$CM+ $OP; # The $CM+ is from rule 10, an unattached CM is treated as AL.
341 $CP $CM* ($ALPlus | $HL | $NU);
343 # LB 30a Do not break between regional indicators. Break after pairs of them.
344 # Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM.
345 $RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
346 $RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
347 $RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $ZWJ {eof}];
348 # note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?'
349 # because of the chain-out behavior difference. The rule must chain out only from the [set characters],
350 # not from the preceding $RI or $CM, which it would be able to do if the set were optional.
352 # LB 30b Do not break between an Emoji Base and an Emoji Modifier
355 # LB 31 Break everywhere else.
356 # Match a single code point if no other rule applies.