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_normal_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=normal (BCP47 -u-lb-normal) 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)
26 # Character Classes defined by TR 14.
30 !!quoted_literals_only;
32 $AI = [:LineBreak = Ambiguous:];
33 $AL = [:LineBreak = Alphabetic:];
34 $BAX = [\u2010 \u2013];
35 $BA = [[:LineBreak = Break_After:] - $BAX];
36 $BB = [:LineBreak = Break_Before:];
37 $BK = [:LineBreak = Mandatory_Break:];
38 $B2 = [:LineBreak = Break_Both:];
39 $CB = [:LineBreak = Contingent_Break:];
40 $CJ = [:LineBreak = Conditional_Japanese_Starter:];
41 $CL = [:LineBreak = Close_Punctuation:];
42 # $CM = [:LineBreak = Combining_Mark:];
43 $CP = [:LineBreak = Close_Parenthesis:];
44 $CR = [:LineBreak = Carriage_Return:];
45 $EB = [[:LineBreak = EB:] \U0001F46A-\U0001F46D\U0001F46F\U0001F91D\U0001F93C];
46 $EM = [:LineBreak = EM:];
47 $EX = [:LineBreak = Exclamation:];
48 $GL = [:LineBreak = Glue:];
49 $HL = [:LineBreak = Hebrew_Letter:];
50 $HY = [:LineBreak = Hyphen:];
51 $H2 = [:LineBreak = H2:];
52 $H3 = [:LineBreak = H3:];
53 # CSS Normal tailoring: CJ resolves to ID
54 $ID = [[:LineBreak = Ideographic:] $CJ];
55 $IN = [:LineBreak = Inseperable:];
56 $IS = [:LineBreak = Infix_Numeric:];
57 $JL = [:LineBreak = JL:];
58 $JV = [:LineBreak = JV:];
59 $JT = [:LineBreak = JT:];
60 $LF = [:LineBreak = Line_Feed:];
61 $NL = [:LineBreak = Next_Line:];
62 $NSX = [\u301C \u30A0];
63 $NS = [[:LineBreak = Nonstarter:] - $NSX];
64 $NU = [:LineBreak = Numeric:];
65 $OP = [:LineBreak = Open_Punctuation:];
66 $PO = [:LineBreak = Postfix_Numeric:];
67 $PR = [:LineBreak = Prefix_Numeric:];
68 $QU = [:LineBreak = Quotation:];
69 $RI = [:LineBreak = Regional_Indicator:];
70 $SA = [:LineBreak = Complex_Context:];
71 $SG = [:LineBreak = Surrogate:];
72 $SP = [:LineBreak = Space:];
73 $SY = [:LineBreak = Break_Symbols:];
74 $WJ = [:LineBreak = Word_Joiner:];
75 $XX = [:LineBreak = Unknown:];
76 $ZW = [:LineBreak = ZWSpace:];
77 $ZWJ = [:LineBreak = ZWJ:];
79 # By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly
80 # list it in the numerous rules that use CM.
81 # By LB1, SA characters with general categor of Mn or Mc also resolve to CM.
83 $CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]];
85 # Dictionary character set, for triggering language-based break engines. Currently
86 # limited to LineBreak=Complex_Context (SA).
91 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
92 # SA (Dictionary chars, excluding Mn and Mc)
93 # SG (Unpaired Surrogates)
94 # XX (Unknown, unassigned)
97 $ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]];
100 ## -------------------------------------------------
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.
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.
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
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.
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];
121 # Rule LB 4, 5 Mandatory (Hard) breaks.
123 $LB4Breaks = [$BK $CR $LF $NL];
124 $LB4NonBreaks = [^$BK $CR $LF $NL $CM];
128 # LB 6 Do not break before hard line breaks.
130 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
131 $CAN_CM $CM* $LB4Breaks {100};
132 ^$CM+ $LB4Breaks {100};
136 $LB4NonBreaks [$SP $ZW];
137 $CAN_CM $CM* [$SP $ZW];
141 # LB 8 Break after zero width space
142 # TODO: ZW SP* <break>
143 # An engine change is required to write the reverse rule for this.
144 # For now, leave the Unicode 5.2 rule, ZW <break>
146 $LB8Breaks = [$LB4Breaks $ZW];
147 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
149 # LB 8a ZWJ x Do not break Emoji ZWJ sequences.
153 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
154 # $CM not covered by the above needs to behave like $AL
155 # See definition of $CAN_CM.
157 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
161 # LB 11 Do not break before or after WORD JOINER & related characters.
170 # LB 12 Do not break after NBSP and related characters.
176 # LB 12a Do not break before NBSP and related characters ...
179 [[$LB8NonBreaks] - [$SP $BA $BAX $HY]] $CM* $GL;
185 # LB 13 Don't break before ']' or '!' or ';' or '/', even after spaces.
189 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
193 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
197 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
201 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
205 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
209 # LB 14 Do not break after OP, even after spaces
213 $OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
214 # by rule 8, CM following a SP is stand-alone.
220 # Do not break between closing punctuation and $NS, even with intervening spaces
221 # But DO allow a break between closing punctuation and $NSX, don't include it here
222 ($CL | $CP) $CM* $SP* $NS;
228 # LB 18 Break after spaces.
230 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
231 $LB18Breaks = [$LB8Breaks $SP];
236 $LB18NonBreaks $CM* $QU;
247 $LB20NonBreaks = [$LB18NonBreaks - $CB];
249 # LB 21 x (BA | HY | NS)
252 # DO allow breaks here before $BAXcm and $NSXcm, so don't include them
253 $LB20NonBreaks $CM* ($BA | $HY | $NS);
254 ^$CM+ ($BA | $HY | $NS);
256 $BB $CM* [^$CB]; # $BB x
257 $BB $CM* $LB20NonBreaks;
259 # LB 21a Don't break after Hebrew + Hyphen
262 $HL $CM* ($HY | $BA | $BAX) $CM* [^$CB]?;
264 # LB 21b (forward) Don't break between SY and HL
265 # (break between HL and SY already disallowed by LB 13 above)
269 ($ALPlus | $HL) $CM* $IN;
270 ^$CM+ $IN; # by rule 10, any otherwise unattached CM behaves as AL
272 ($ID | $EB | $EM) $CM* $IN;
279 ($ALPlus | $HL) $CM* $NU;
280 ^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL
281 $NU $CM* ($ALPlus | $HL);
285 $PR $CM* ($ID | $EB | $EM);
286 ($ID | $EB | $EM) $CM* $PO;
292 ($PR | $PO) $CM* ($ALPlus | $HL);
293 ($ALPlus | $HL) $CM* ($PR | $PO);
294 ^$CM+ ($PR | $PO); # Rule 10, any otherwise unattached CM behaves as AL
299 (($PR | $PO) $CM*)? (($OP | $HY) $CM*)? $NU ($CM* ($NU | $SY | $IS))*
300 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?;
302 # LB 26 Do not break a Korean syllable
304 $JL $CM* ($JL | $JV | $H2 | $H3);
305 ($JV | $H2) $CM* ($JV | $JT);
306 ($JT | $H3) $CM* $JT;
308 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
309 ($JL | $JV | $JT | $H2 | $H3) $CM* $IN;
310 ($JL | $JV | $JT | $H2 | $H3) $CM* $PO;
311 $PR $CM* ($JL | $JV | $JT | $H2 | $H3);
314 # LB 28 Do not break between alphabetics
316 ($ALPlus | $HL) $CM* ($ALPlus | $HL);
317 ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL
320 $IS $CM* ($ALPlus | $HL);
323 ($ALPlus | $HL | $NU) $CM* $OP;
324 ^$CM+ $OP; # The $CM+ is from rule 10, an unattached CM is treated as AL.
325 $CP $CM* ($ALPlus | $HL | $NU);
327 # LB 30a Do not break between regional indicators. Break after pairs of them.
328 # Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM.
329 $RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
330 $RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
331 $RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $ZWJ {eof}];
332 # note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?'
333 # because of the chain-out behavior difference. The rule must chain out only from the [set characters],
334 # not from the preceding $RI or $CM, which it would be able to do if the set were optional.
336 # LB 30b Do not break between an Emoji Base and an Emoji Modifier
339 # LB 31 Break everywhere else.
340 # Match a single code point if no other rule applies.