1 # Copyright (c) 2002-2016 International Business Machines Corporation and
2 # others. All Rights Reserved.
4 # file: line_normal_cj.txt
7 # Implement default line breaking as defined by
8 # Unicode Standard Annex #14 Revision 35 for Unicode 8.0
9 # http://www.unicode.org/reports/tr14/
11 # Includes the Emoji breaking proposals from Unicode L2/16-011R3.
12 # http://www.unicode.org/L2/L2016/16011r3-break-prop-emoji.pdf
14 # tailored as noted in 2nd paragraph below.
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.
20 # This tailors the line break behavior to correspond to CSS
21 # line-break=normal (BCP47 -u-lb-normal) as defined for Chinese & Japanese.
22 # It sets characters of class CJ to behave like ID.
23 # In addition, it allows breaks:
24 # * before hyphens 2010 & 2013 (both BA) and 301C, 30A0 (both NS)
27 # Character Classes defined by TR 14.
34 # !!lookAheadHardBreak Described here because it is (as yet) undocumented elsewhere
35 # and only used for the line break rules.
37 # It is used in the implementation of rule LB 10
38 # which says to treat any combining mark that is not attached to a base
39 # character as if it were of class AL (alphabetic).
41 # The problem occurs in the reverse rules.
43 # Consider a sequence like, with correct breaks as shown
46 # Then consider the sequence without the initial ID (ideographic)
49 # Our CM, which in the first example was attached to the ideograph,
50 # is now unattached, becomes an alpha, and joins in with the other
53 # When iterating forwards, these sequences do not present any problems
54 # When iterating backwards, we need to look ahead when encountering
55 # a CM to see whether it attaches to something further on or not.
56 # (Look-ahead in a reverse rule is looking towards the start)
58 # If the CM is unattached, we need to force a break.
60 # !!lookAheadHardBreak forces the run time state machine to
61 # stop immediately when a look ahead rule ( '/' operator) matches,
62 # and set the match position to that of the look-ahead operator,
63 # no matter what other rules may be in play at the time.
65 # See rule LB 19 for an example.
68 # Temporary definitions of Emoji Base and Emoji Modifiers, until properties are available.
70 $EB = [\u261D\u26F9\u270A-\u270D\U0001F385\U0001F3C3-\U0001F3C4\U0001F3CA-\U0001F3CB\U0001F442-\U0001F443\U0001F446-\U0001F450\U0001F466-\U0001F469\U0001F46E\U0001F470-\U0001F478\U0001F47C\U0001F481-\U0001F483\U0001F485-\U0001F487\U0001F4AA\U0001F575\U0001F590\U0001F595-\U0001F596\U0001F645-\U0001F647\U0001F64B-\U0001F64F\U0001F6A3\U0001F6B4-\U0001F6B6\U0001F6C0\U0001F918];
71 $EM = [\U0001F3FB-\U0001F3FF];
73 $AI = [[:LineBreak = Ambiguous:] - [\u2640\u2642]];
74 $AL = [[:LineBreak = Alphabetic:] - [$EM\u2764]];
75 $BAX = [\u2010 \u2013];
76 $BA = [[:LineBreak = Break_After:] - $BAX];
77 $BB = [:LineBreak = Break_Before:];
78 $BK = [:LineBreak = Mandatory_Break:];
79 $B2 = [:LineBreak = Break_Both:];
80 $CB = [:LineBreak = Contingent_Break:];
81 $CJ = [:LineBreak = Conditional_Japanese_Starter:];
82 $CL = [:LineBreak = Close_Punctuation:];
83 $CM = [[:LineBreak = Combining_Mark:] \u200d];
84 $CP = [:LineBreak = Close_Parenthesis:];
85 $CR = [:LineBreak = Carriage_Return:];
86 $EX = [:LineBreak = Exclamation:];
87 $GL = [:LineBreak = Glue:];
88 $HL = [:LineBreak = Hebrew_Letter:];
89 $HY = [:LineBreak = Hyphen:];
90 $H2 = [:LineBreak = H2:];
91 $H3 = [:LineBreak = H3:];
92 $ID = [[:LineBreak = Ideographic:] $CJ [\u2640\u2642\u2764] - $EB];
93 $IN = [:LineBreak = Inseperable:];
94 $IS = [:LineBreak = Infix_Numeric:];
95 $JL = [:LineBreak = JL:];
96 $JV = [:LineBreak = JV:];
97 $JT = [:LineBreak = JT:];
98 $LF = [:LineBreak = Line_Feed:];
99 $NL = [:LineBreak = Next_Line:];
100 $NSX = [\u301C \u30A0];
101 $NS = [[:LineBreak = Nonstarter:] - $NSX];
102 $NU = [:LineBreak = Numeric:];
103 $OP = [:LineBreak = Open_Punctuation:];
104 $PO = [:LineBreak = Postfix_Numeric:];
105 $PR = [:LineBreak = Prefix_Numeric:];
106 $QU = [:LineBreak = Quotation:];
107 $RI = [:LineBreak = Regional_Indicator:];
108 $SA = [:LineBreak = Complex_Context:];
109 $SG = [:LineBreak = Surrogate:];
110 $SP = [:LineBreak = Space:];
111 $SY = [:LineBreak = Break_Symbols:];
112 $WJ = [:LineBreak = Word_Joiner:];
113 $XX = [:LineBreak = Unknown:];
114 $ZW = [:LineBreak = ZWSpace:];
117 # Dictionary character set, for triggering language-based break engines. Currently
118 # limited to LineBreak=Complex_Context. Note that this set only works in Unicode
119 # 5.0 or later as the definition of Complex_Context was corrected to include all
120 # characters requiring dictionary break.
122 $dictionary = [:LineBreak = Complex_Context:];
125 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
126 # SA (South East Asian: Thai, Lao, Khmer)
127 # SG (Unpaired Surrogates)
128 # XX (Unknown, unassigned)
129 # as $AL (Alphabetic)
131 $ALPlus = [$AL $AI $SA $SG $XX];
134 # Combining Marks. X $CM* behaves as if it were X. Rule LB6.
136 $ALcm = $ALPlus $CM*;
165 ## -------------------------------------------------
170 # Each class of character can stand by itself as an unbroken token, with trailing combining stuff
205 # CAN_CM is the set of characters that may combine with CM combining chars.
206 # Note that Linebreak UAX 14's concept of a combining char and the rules
207 # for what they can combine with are _very_ different from the rest of Unicode.
209 # Note that $CM itself is left out of this set. If CM is needed as a base
210 # it must be listed separately in the rule.
212 $CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs
213 $CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs
216 # AL_FOLLOW set of chars that can unconditionally follow an AL
217 # Needed in rules where stand-alone $CM s are treated as AL.
218 # Chaining is disabled with CM because it causes other failures,
219 # so for this one case we need to manually list out longer sequences.
221 $AL_FOLLOW_NOCM = [$BK $CR $LF $NL $ZW $SP];
222 $AL_FOLLOW_CM = [$CL $CP $EX $HL $IS $SY $WJ $GL $OP $QU $BA $HY $NS $IN $NU $ALPlus];
223 $AL_FOLLOW = [$AL_FOLLOW_NOCM $AL_FOLLOW_CM];
227 # Rule LB 4, 5 Mandatory (Hard) breaks.
229 $LB4Breaks = [$BK $CR $LF $NL];
230 $LB4NonBreaks = [^$BK $CR $LF $NL $CM];
234 # LB 6 Do not break before hard line breaks.
236 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
237 $CAN_CM $CM* $LB4Breaks {100};
238 ^$CM+ $LB4Breaks {100};
242 $LB4NonBreaks [$SP $ZW];
243 $CAN_CM $CM* [$SP $ZW];
247 # LB 8 Break after zero width space
248 # TODO: ZW SP* <break>
249 # An engine change is required to write the reverse rule for this.
250 # For now, leave the Unicode 5.2 rule, ZW <break>
252 $LB8Breaks = [$LB4Breaks $ZW];
253 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
255 # LB 8a ZWJ x ID Emoji proposal.
257 $ZWJ ($ID | $EB | $EM);
259 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
260 # $CM not covered by the above needs to behave like $AL
261 # See definition of $CAN_CM.
263 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
267 # LB 11 Do not break before or after WORD JOINER & related characters.
277 # LB 12 Do not break after NBSP and related characters.
284 # LB 12a Do not break before NBSP and related characters ...
287 [[$LB8NonBreaks] - [$SP $BA $BAX $HY]] $CM* $GLcm;
293 # LB 13 Don't break before ']' or '!' or ';' or '/', even after spaces.
297 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
301 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
305 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
309 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
313 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
317 # LB 14 Do not break after OP, even after spaces
319 $OPcm $SP* $CAN_CM $CM*;
322 $OPcm $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
328 # Do not break between closing punctuation and $NS, even with intervening spaces
329 # But DO allow a break between closing punctuation and $NSX, don't include it here
330 ($CLcm | $CPcm) $SP* $NScm;
336 # LB 18 Break after spaces.
338 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
339 $LB18Breaks = [$LB8Breaks $SP];
344 $LB18NonBreaks $CM* $QUcm;
355 $LB20NonBreaks = [$LB18NonBreaks - $CB];
357 # LB 21 x (BA | HY | NS)
360 # DO allow breaks here before $BAXcm and $NSXcm, so don't include them
361 $LB20NonBreaks $CM* ($BAcm | $HYcm | $NScm);
362 ^$CM+ ($BAcm | $HYcm | $NScm);
364 $BBcm [^$CB]; # $BB x
365 $BBcm $LB20NonBreaks $CM*;
367 # LB 21a Don't break after Hebrew + Hyphen
370 $HLcm ($HYcm | $BAcm | $BAXcm) [^$CB]?;
372 # LB 21b (forward) Don't break between SY and HL
373 # (break between HL and SY already disallowed by LB 13 above)
377 ($ALcm | $HLcm) $INcm;
378 ^$CM+ $INcm; # by rule 10, any otherwise unattached CM behaves as AL
380 ($ID | $EB | $EM) $CM* $INcm;
386 ($ID | $EB | $EM) $CM* $POcm;
387 $ALcm $NUcm; # includes $LB19
389 ^$CM+ $NUcm; # Rule 10, any otherwise unattached CM behaves as AL
396 $PRcm ($ID | $EB | $EM);
397 $PRcm ($ALcm | $HLcm);
398 $POcm ($ALcm | $HLcm);
399 ($ALcm | $HLcm) ($PRcm | $POcm);
400 ^$CM+ ($PRcm | $POcm); # Rule 10, any otherwise unattached CM behaves as AL
405 ($PRcm | $POcm)? ($OPcm | $HYcm)? $NUcm ($NUcm | $SYcm | $IScm)* ($CLcm | $CPcm)? ($PRcm | $POcm)?;
407 # LB 26 Do not break a Korean syllable
409 $JLcm ($JLcm | $JVcm | $H2cm | $H3cm);
410 ($JVcm | $H2cm) ($JVcm | $JTcm);
411 ($JTcm | $H3cm) $JTcm;
413 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
414 ($JLcm | $JVcm | $JTcm | $H2cm | $H3cm) $INcm;
415 ($JLcm | $JVcm | $JTcm | $H2cm | $H3cm) $POcm;
416 $PRcm ($JLcm | $JVcm | $JTcm | $H2cm | $H3cm);
419 # LB 28 Do not break between alphabetics
421 ($ALcm | $HLcm) ($ALcm | $HLcm);
422 ^$CM+ ($ALcm | $HLcm); # The $CM+ is from rule 10, an unattached CM is treated as AL
425 $IScm ($ALcm | $HLcm);
428 ($ALcm | $HLcm | $NUcm) $OPcm;
429 ^$CM+ $OPcm; # The $CM+ is from rule 10, an unattached CM is treated as AL.
430 $CPcm ($ALcm | $HLcm | $NUcm);
432 # LB 30a Do not break between regional indicators. Break after pairs of them.
433 # Tricky interaction with LB8a: ZWJ x ID
434 $RIcm $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM] {eof}];
435 $RIcm $RI $CM* $ZWJ / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM $ID $EB $EM] {eof}];
436 $RIcm $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM] {eof}];
438 $RIcm $RIcm [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS {eof}];
439 $RIcm $RIcm $ZWJ ($ID | $EB | $EM);
441 # LB 30b Do not break between an Emoji Base and an Emoji Modifier
447 ## -------------------------------------------------
486 # Sequences of the form (shown forwards)
487 # [CANT_CM] <break> [CM] [whatever]
488 # The CM needs to behave as an AL
491 [$BK $CR $LF $NL $ZW {eof}] |
493 $SP+ $CM* ([^$OP $CM $SP] | [$AL {eof}])); # if LB 14 will match, need to surpress this break.
494 # LB14 says OP SP* x .
495 # becomes OP SP* x AL
496 # becomes OP SP* x CM+ AL_FOLLOW
498 # Further note: the $AL in [$AL {eof}] is only to work around
499 # a rule compiler bug which complains about
500 # empty sets otherwise.
503 # Sequences of the form (shown forwards)
504 # [CANT_CM] <break> [CM] <break> [PR]
505 # The CM needs to behave as an AL
506 # This rule is concerned about getting the second of the two <breaks> in place.
509 # Apple early addition, remove this, superseded by LB24
510 # [$PR ] / $CM+ [$BK $CR $LF $NL $ZW $SP {eof}];
516 $LB4Breaks [$LB4NonBreaks-$CM];
517 $LB4Breaks $CM+ $CAN_CM;
523 [$SP $ZW] [$LB4NonBreaks-$CM];
524 [$SP $ZW] $CM+ $CAN_CM;
526 # LB 8 ZW SP* <break>
527 # TODO: to implement this, we need more than one look-ahead hard break in play at a time.
528 # Requires an engine enhancement.
531 # LB 8a ZWJ x ID Unicode Emoji proposal L2/16-011R3
532 # The ZWJ will look like a CM to whatever precedes it.
534 ($ID | $EB | $EM) $ZWJ $CM* $CAN_CM?;
537 # LB 9,10 Combining marks.
538 # X $CM needs to behave like X, where X is not $SP or controls.
539 # $CM not covered by the above needs to behave like $AL
540 # Stick together any combining sequences that don't match other rules.
547 $WJ [$LB8NonBreaks-$CM];
555 $GL $CM* [$LB8NonBreaks-[$CM $SP $BA $BAX $HY]];
571 $CL [$LB8NonBreaks-$CM];
572 $CP [$LB8NonBreaks-$CM];
573 $EX [$LB8NonBreaks-$CM];
574 $IS [$LB8NonBreaks-$CM];
575 $SY [$LB8NonBreaks-$CM];
577 # Rule 13 & 14 taken together for an edge case.
578 # Match this, shown forward
579 # OP SP+ ($CM+ behaving as $AL) (CL | CP | EX | IS | IY)
580 # This really wants to chain at the $CM+ (which is acting as an $AL)
581 # except for $CM chaining being disabled.
582 [$CL $CP $EX $IS $SY] $CM+ $SP+ $CM* $OP;
586 $CAN_CM $SP* $CM* $OP;
587 $CANT_CM $SP* $CM* $OP;
588 $AL_FOLLOW? $CM+ $SP $SP* $CM* $OP; # by LB 10, behaves like $AL_FOLLOW? $AL $SP* $CM* $OP
590 $AL_FOLLOW_NOCM $CM+ $SP+ $CM* $OP;
591 $AL_FOLLOW_CM $CM+ $SP+ $CM* $OP;
598 # Don't include $NSX here
599 $NS $SP* $CM* ($CL | $CP);
604 # LB 18 break after spaces
605 # Nothing explicit needed here.
611 $QU $CM* $CAN_CM; # . x QU
615 $CAN_CM $CM* $QU; # QU x .
619 # LB 20 Break before and after CB.
620 # nothing needed here.
624 # Don't include $BAX or $NSX here
625 ($BA | $HY | $NS) $CM* [$LB20NonBreaks-$CM]; # . x (BA | HY | NS)
627 [$LB20NonBreaks-$CM] $CM* $BB; # BB x .
630 # LB21a Don't break after Hebrew + Hyphen.
631 ([^$CB] $CM*)? ($HY | $BA | $BAX) $CM* $HL;
637 $IN $CM* ($ALPlus | $HL);
639 $IN $CM* ($ID | $EB | $EM);
644 $PO $CM* ($ID | $EB | $EM);
645 $NU $CM* ($ALPlus | $HL);
646 ($ALPlus | $HL) $CM* $NU;
649 ($ID | $EB | $EM) $CM* $PR;
650 ($ALPlus | $HL) $CM* $PR;
651 ($ALPlus | $HL) $CM* $PO;
652 $CM* ($PR | $PO) $CM* ($ALPlus | $HL);
653 $CM* ($PR | $PO) $CM+ / [$BK $CR $LF $NL $ZW $SP {eof}];
656 ($CM* ($PR | $PO))? ($CM* ($CL | $CP))? ($CM* ($NU | $IS | $SY))* $CM* $NU ($CM* ($OP | $HY))? ($CM* ($PR | $PO))?;
659 ($H3 | $H2 | $JV | $JL) $CM* $JL;
660 ($JT | $JV) $CM* ($H2 | $JV);
661 $JT $CM* ($H3 | $JT);
664 $IN $CM* ($H3 | $H2 | $JT | $JV | $JL);
665 $PO $CM* ($H3 | $H2 | $JT | $JV | $JL);
666 ($H3 | $H2 | $JT | $JV | $JL) $CM* $PR;
669 ($ALPlus | $HL) $CM* ($ALPlus | $HL);
673 ($ALPlus | $HL) $CM* $IS;
676 $OP $CM* ($ALPlus | $HL | $NU);
677 ($ALPlus | $HL | $NU) $CM* $CP;
680 # Pairs of Regional Indicators.
681 # The following two rules are nearly identical. The first matches only sequences with an odd number of adjacent RIs,
682 # the second with an even number. Stripping away the cruft they look like
683 # [^RI] RI / (RI RI)+ ^RI;
684 # [^RI] RI RI / (RI RI)+ ^RI;
686 [{bof} $NS $HY $BA $QU $CL $CP $EX $IS $SY $WJ $GL $ZW $SP $BK $CR $LF $NL $ZWJ] $CM* $RI / ($CM* $RI $CM* $RI)+ $CM* [{eof}[^$RI $CM]];
687 [{bof} $NS $HY $BA $QU $CL $CP $EX $IS $SY $WJ $GL $ZW $SP $BK $CR $LF $NL $ZWJ] $CM* $RI $CM* $RI / ($CM* $RI $CM* $RI)+ $CM* [{eof}[^$RI $CM]];
689 # In general, adjacent RIs stay together. The hard-break rules, above, overide this, forcing in the boundaries between pairs.
692 # WJ, GL, QU, etc. are classes with rules like "WJ x " which includes "WJ x RI".
693 $RI $CM* ([$WJ $GL $QU $BB] | (($HY | $BA)$CM* $HL));
696 # LB 30b Do not break between an Emoji Base and an Emoji Modifier
700 ## -------------------------------------------------
705 ^$CM+ [^$CM $BK $CR $LF $NL $ZW $SP];
715 $SP+ $CM* ($CL | $CP);
721 $CM* ($HY | $BA | $BAX) $CM* $HL;
724 ($CM* ($IS | $SY))+ $CM* $NU;
725 ($CL | $CP) $CM* ($NU | $IS | $SY);
730 # For dictionary-based break
731 $dictionary $dictionary;
733 ## -------------------------------------------------
737 # Skip forward over all character classes that are involved in
738 # rules containing patterns with possibly more than one char
741 # It might be slightly more efficient to have specific rules
742 # instead of one generic one, but only if we could
743 # turn off rule chaining. We don't want to move more
746 ^[$CM $OP $QU $CL $CP $B2 $PR $HY $BA $BAX $SP $RI $ZWJ $dictionary]+ [^$CM $OP $QU $CL $CP $B2 $PR $HY $BA $BAX $RI $ZWJ $dictionary];
747 $dictionary $dictionary;