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.
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 corresponds to CSS line-break=strict (BCP47 -u-lb-strict).
17 # It sets characters of class CJ to behave like NS.
20 # Character Classes defined by TR 14.
24 !!quoted_literals_only;
26 $AI = [:LineBreak = Ambiguous:];
27 $AL = [:LineBreak = Alphabetic:];
28 $BA = [:LineBreak = Break_After:];
29 $HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA.
30 $BB = [:LineBreak = Break_Before:];
31 $BK = [:LineBreak = Mandatory_Break:];
32 $B2 = [:LineBreak = Break_Both:];
33 $CB = [:LineBreak = Contingent_Break:];
34 $CJ = [:LineBreak = Conditional_Japanese_Starter:];
35 $CL = [:LineBreak = Close_Punctuation:];
36 # $CM = [:LineBreak = Combining_Mark:];
37 $CP = [:LineBreak = Close_Parenthesis:];
38 $CR = [:LineBreak = Carriage_Return:];
39 $EB = [:LineBreak = EB:];
40 $EM = [:LineBreak = EM:];
41 $EX = [:LineBreak = Exclamation:];
42 $GL = [:LineBreak = Glue:];
43 $HL = [:LineBreak = Hebrew_Letter:];
44 $HY = [:LineBreak = Hyphen:];
45 $H2 = [:LineBreak = H2:];
46 $H3 = [:LineBreak = H3:];
47 $ID = [:LineBreak = Ideographic:];
48 $IN = [:LineBreak = Inseperable:];
49 $IS = [:LineBreak = Infix_Numeric:];
50 $JL = [:LineBreak = JL:];
51 $JV = [:LineBreak = JV:];
52 $JT = [:LineBreak = JT:];
53 $LF = [:LineBreak = Line_Feed:];
54 $NL = [:LineBreak = Next_Line:];
55 # NS includes CJ for CSS strict line breaking.
56 $NS = [[:LineBreak = Nonstarter:] $CJ];
57 $NU = [:LineBreak = Numeric:];
58 $OP = [:LineBreak = Open_Punctuation:];
59 $PO = [:LineBreak = Postfix_Numeric:];
60 $PR = [:LineBreak = Prefix_Numeric:];
61 $QU = [:LineBreak = Quotation:];
62 $RI = [:LineBreak = Regional_Indicator:];
63 $SA = [:LineBreak = Complex_Context:];
64 $SG = [:LineBreak = Surrogate:];
65 $SP = [:LineBreak = Space:];
66 $SY = [:LineBreak = Break_Symbols:];
67 $WJ = [:LineBreak = Word_Joiner:];
68 $XX = [:LineBreak = Unknown:];
69 $ZW = [:LineBreak = ZWSpace:];
70 $ZWJ = [:LineBreak = ZWJ:];
72 # The following classes are no longer needed for ICU rules but may
73 # still be needed for WebKit rules in lineClasses.txt
74 # $EmojiNRK = [[\p{Emoji}] - [$RI \u002a\u00230-9©®™〰〽]];
75 # $Extended_Pict = [:ExtPict:];
77 # By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly
78 # list it in the numerous rules that use CM.
79 # By LB1, SA characters with general categor of Mn or Mc also resolve to CM.
81 $CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]];
82 $CMX = [[$CM] - [$ZWJ]];
84 # Dictionary character set, for triggering language-based break engines. Currently
85 # limited to LineBreak=Complex_Context (SA).
90 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
91 # SA (Dictionary chars, excluding Mn and Mc)
92 # SG (Unpaired Surrogates)
93 # XX (Unknown, unassigned)
96 $ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]];
99 ## -------------------------------------------------
102 # CAN_CM is the set of characters that may combine with CM combining chars.
103 # Note that Linebreak UAX 14's concept of a combining char and the rules
104 # for what they can combine with are _very_ different from the rest of Unicode.
106 # Note that $CM itself is left out of this set. If CM is needed as a base
107 # it must be listed separately in the rule.
109 $CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs
110 $CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs
113 # AL_FOLLOW set of chars that can unconditionally follow an AL
114 # Needed in rules where stand-alone $CM s are treated as AL.
116 $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 # Rule LB 4, 5 Mandatory (Hard) breaks.
122 $LB4Breaks = [$BK $CR $LF $NL];
123 $LB4NonBreaks = [^$BK $CR $LF $NL $CM];
127 # LB 6 Do not break before hard line breaks.
129 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
130 $CAN_CM $CM* $LB4Breaks {100};
131 ^$CM+ $LB4Breaks {100};
135 $LB4NonBreaks [$SP $ZW];
136 $CAN_CM $CM* [$SP $ZW];
140 # LB 8 Break after zero width space
143 $LB8Breaks = [$LB4Breaks $ZW];
144 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
145 $ZW $SP* / [^$SP $ZW $LB4Breaks];
147 # LB 8a ZWJ x Do not break Emoji ZWJ sequences.
151 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
152 # $CM not covered by the above needs to behave like $AL
153 # See definition of $CAN_CM.
155 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
159 # LB 11 Do not break before or after WORD JOINER & related characters.
168 # LB 12 Do not break after NBSP and related characters.
174 # LB 12a Do not break before NBSP and related characters ...
177 [[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GL;
183 # LB 13 Don't break before ']' or '!' or or '/', even after spaces.
187 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
191 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
195 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
199 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
203 # LB 14 Do not break after OP, even after spaces
204 # Note subtle interaction with "SP IS /" rules in LB14a.
205 # This rule consumes the SP, chaining happens on the IS, effectivley overriding the SP IS rules,
206 # which is the desired behavior.
210 $OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
211 # by rule 8, CM following a SP is stand-alone.
214 # LB 14a Force a break before start of a number with a leading decimal pt, e.g. " .23"
215 # Note: would be simpler to express as "$SP / $IS $CM* $NU;", but ICU rules have limitations.
216 # See issue ICU-20303
219 $CanFollowIS = [$BK $CR $LF $NL $SP $ZW $WJ $GL $CL $CP $EX $IS $SY $QU $BA $HY $NS $ALPlus $HL];
220 $SP $IS / [^ $CanFollowIS $NU $CM];
221 $SP $IS $CM* $CMX / [^ $CanFollowIS $NU $CM];
224 # LB 14b Do not break before numeric separators (IS), even after spaces.
226 [$LB8NonBreaks - $SP] $IS;
227 $SP $IS $CM* [$CanFollowIS {eof}];
228 $SP $IS $CM* $ZWJ [^$CM $NU];
231 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
238 ($CL | $CP) $CM* $SP* $NS;
244 # LB 18 Break after spaces.
246 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
247 $LB18Breaks = [$LB8Breaks $SP];
252 $LB18NonBreaks $CM* $QU;
262 $LB20NonBreaks = [$LB18NonBreaks - $CB];
264 # LB 20.09 Don't break between Hyphens and Letters when there is a break preceding the hyphen.
265 # Originally added as a Finnish tailoring, now promoted to default ICU behavior.
266 # Note: this is not default UAX-14 behaviour. See issue ICU-8151.
268 ^($HY | $HH) $CM* $ALPlus;
270 # LB 21 x (BA | HY | NS)
273 $LB20NonBreaks $CM* ($BA | $HY | $NS);
276 ^$CM+ ($BA | $HY | $NS);
278 $BB $CM* [^$CB]; # $BB x
279 $BB $CM* $LB20NonBreaks;
281 # LB 21a Don't break after Hebrew + Hyphen
284 $HL $CM* ($HY | $BA) $CM* [^$CB]?;
286 # LB 21b (forward) Don't break between SY and HL
287 # (break between HL and SY already disallowed by LB 13 above)
291 ($ALPlus | $HL) $CM* $IN;
292 ^$CM+ $IN; # by rule 10, any otherwise unattached CM behaves as AL
294 ($ID | $EB | $EM) $CM* $IN;
301 ($ALPlus | $HL) $CM* $NU;
302 ^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL
303 $NU $CM* ($ALPlus | $HL);
307 $PR $CM* ($ID | $EB | $EM);
308 ($ID | $EB | $EM) $CM* $PO;
314 ($PR | $PO) $CM* ($ALPlus | $HL);
315 ($ALPlus | $HL) $CM* ($PR | $PO);
316 ^$CM+ ($PR | $PO); # Rule 10, any otherwise unattached CM behaves as AL
321 (($PR | $PO) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))*
322 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?;
324 # LB 26 Do not break a Korean syllable
326 $JL $CM* ($JL | $JV | $H2 | $H3);
327 ($JV | $H2) $CM* ($JV | $JT);
328 ($JT | $H3) $CM* $JT;
330 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
331 ($JL | $JV | $JT | $H2 | $H3) $CM* $IN;
332 ($JL | $JV | $JT | $H2 | $H3) $CM* $PO;
333 $PR $CM* ($JL | $JV | $JT | $H2 | $H3);
336 # LB 28 Do not break between alphabetics
338 ($ALPlus | $HL) $CM* ($ALPlus | $HL);
339 ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL
342 $IS $CM* ($ALPlus | $HL);
345 ($ALPlus | $HL | $NU) $CM* $OP;
346 ^$CM+ $OP; # The $CM+ is from rule 10, an unattached CM is treated as AL.
347 $CP $CM* ($ALPlus | $HL | $NU);
349 # LB 30a Do not break between regional indicators. Break after pairs of them.
350 # Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM.
351 $RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
352 $RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
353 $RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $ZWJ {eof}];
354 # note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?'
355 # because of the chain-out behavior difference. The rule must chain out only from the [set characters],
356 # not from the preceding $RI or $CM, which it would be able to do if the set were optional.
358 # LB 30b Do not break between an Emoji Base and an Emoji Modifier
361 # LB 31 Break everywhere else.
362 # Match a single code point if no other rule applies.