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 42 for Unicode 12.0
11 # http://www.unicode.org/reports/tr14/, with the following modification:
13 # Boundaries between hyphens and following letters are suppressed when
14 # there is a boundary preceding the hyphen. See rule 20.9
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)
21 # It allows breaking before 201C and after 201D, for zh_Hans, zh_Hant, and ja.
24 # Character Classes defined by TR 14.
28 !!quoted_literals_only;
30 $AI = [:LineBreak = Ambiguous:];
31 $AL = [:LineBreak = Alphabetic:];
32 $BAX = [\u2010 \u2013];
33 $BA = [[:LineBreak = Break_After:] - $BAX];
34 $HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA.
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:];
40 $CL = [[:LineBreak = Close_Punctuation:] \u201d];
41 # $CM = [:LineBreak = Combining_Mark:];
42 $CP = [:LineBreak = Close_Parenthesis:];
43 $CR = [:LineBreak = Carriage_Return:];
44 $EB = [:LineBreak = EB:];
45 $EM = [:LineBreak = EM:];
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:];
52 # CSS Normal tailoring: CJ resolves to ID
53 $ID = [[:LineBreak = Ideographic:] $CJ];
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:];
64 $OP = [[:LineBreak = Open_Punctuation:] \u201c];
65 $PO = [:LineBreak = Postfix_Numeric:];
66 $PR = [:LineBreak = Prefix_Numeric:];
67 $QU = [[:LineBreak = Quotation:] - [\u201c\u201d]];
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:];
76 $ZWJ = [:LineBreak = ZWJ:];
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.
82 $CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]];
83 $CMX = [[$CM] - [$ZWJ]];
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
144 $LB8Breaks = [$LB4Breaks $ZW];
145 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
146 $ZW $SP* / [^$SP $ZW $LB4Breaks];
148 # LB 8a ZWJ x Do not break Emoji ZWJ sequences.
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
154 # See definition of $CAN_CM.
156 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
160 # LB 11 Do not break before or after WORD JOINER & related characters.
169 # LB 12 Do not break after NBSP and related characters.
175 # LB 12a Do not break before NBSP and related characters ...
178 [[$LB8NonBreaks] - [$SP $BA $BAX $HY]] $CM* $GL;
184 # LB 13 Don't break before ']' or '!' or or '/', even after spaces.
188 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
192 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
196 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
200 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
204 # LB 14 Do not break after OP, even after spaces
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.
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.
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
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];
225 # LB 14b Do not break before numeric separators (IS), even after spaces.
227 [$LB8NonBreaks - $SP] $IS;
228 $SP $IS $CM* [$CanFollowIS {eof}];
229 $SP $IS $CM* $ZWJ [^$CM $NU];
232 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
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
241 ($CL | $CP) $CM* $SP* $NS;
247 # LB 18 Break after spaces.
249 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
250 $LB18Breaks = [$LB8Breaks $SP];
255 $LB18NonBreaks $CM* $QU;
265 $LB20NonBreaks = [$LB18NonBreaks - $CB];
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.
271 ^($HY | $HH) $CM* $ALPlus;
273 # LB 21 x (BA | HY | NS)
276 # DO allow breaks here before $BAX and $NSX, so don't include them
277 $LB20NonBreaks $CM* ($BA | $HY | $NS);
280 ^$CM+ ($BA | $HY | $NS);
282 $BB $CM* [^$CB]; # $BB x
283 $BB $CM* $LB20NonBreaks;
285 # LB 21a Don't break after Hebrew + Hyphen
288 $HL $CM* ($HY | $BA | $BAX) $CM* [^$CB]?;
290 # LB 21b (forward) Don't break between SY and HL
291 # (break between HL and SY already disallowed by LB 13 above)
295 ($ALPlus | $HL) $CM* $IN;
296 ^$CM+ $IN; # by rule 10, any otherwise unattached CM behaves as AL
298 ($ID | $EB | $EM) $CM* $IN;
305 ($ALPlus | $HL) $CM* $NU;
306 ^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL
307 $NU $CM* ($ALPlus | $HL);
311 $PR $CM* ($ID | $EB | $EM);
312 ($ID | $EB | $EM) $CM* $PO;
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
325 (($PR | $PO) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))*
326 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?;
328 # LB 26 Do not break a Korean syllable
330 $JL $CM* ($JL | $JV | $H2 | $H3);
331 ($JV | $H2) $CM* ($JV | $JT);
332 ($JT | $H3) $CM* $JT;
334 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
335 ($JL | $JV | $JT | $H2 | $H3) $CM* $IN;
336 ($JL | $JV | $JT | $H2 | $H3) $CM* $PO;
337 $PR $CM* ($JL | $JV | $JT | $H2 | $H3);
340 # LB 28 Do not break between alphabetics
342 ($ALPlus | $HL) $CM* ($ALPlus | $HL);
343 ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL
346 $IS $CM* ($ALPlus | $HL);
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);
353 # LB 30a Do not break between regional indicators. Break after pairs of them.
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.
362 # LB 30b Do not break between an Emoji Base and an Emoji Modifier
365 # LB 31 Break everywhere else.
366 # Match a single code point if no other rule applies.