]> git.saurik.com Git - apple/icu.git/blame_incremental - icuSources/data/brkitr/rules/line_normal.txt
ICU-57149.0.1.tar.gz
[apple/icu.git] / icuSources / data / brkitr / rules / line_normal.txt
... / ...
CommitLineData
1# Copyright (c) 2002-2016 International Business Machines Corporation and
2# others. All Rights Reserved.
3#
4# file: line_normal.txt
5#
6# Line Breaking Rules
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/
10#
11# Includes the Emoji breaking proposals from Unicode L2/16-011R3.
12# http://www.unicode.org/L2/L2016/16011r3-break-prop-emoji.pdf
13#
14# tailored as noted in 2nd paragraph below.
15#
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.
19#
20# This tailors the line break behavior to correspond to CSS
21# line-break=normal (BCP47 -u-lb-normal) as defined for languages other than
22# Chinese & Japanese.
23# It sets characters of class CJ to behave like ID.
24
25#
26# Character Classes defined by TR 14.
27#
28
29!!chain;
30
31!!lookAheadHardBreak;
32#
33# !!lookAheadHardBreak Described here because it is (as yet) undocumented elsewhere
34# and only used for the line break rules.
35#
36# It is used in the implementation of rule LB 10
37# which says to treat any combining mark that is not attached to a base
38# character as if it were of class AL (alphabetic).
39#
40# The problem occurs in the reverse rules.
41#
42# Consider a sequence like, with correct breaks as shown
43# LF ID CM AL AL
44# ^ ^ ^
45# Then consider the sequence without the initial ID (ideographic)
46# LF CM AL AL
47# ^ ^
48# Our CM, which in the first example was attached to the ideograph,
49# is now unattached, becomes an alpha, and joins in with the other
50# alphas.
51#
52# When iterating forwards, these sequences do not present any problems
53# When iterating backwards, we need to look ahead when encountering
54# a CM to see whether it attaches to something further on or not.
55# (Look-ahead in a reverse rule is looking towards the start)
56#
57# If the CM is unattached, we need to force a break.
58#
59# !!lookAheadHardBreak forces the run time state machine to
60# stop immediately when a look ahead rule ( '/' operator) matches,
61# and set the match position to that of the look-ahead operator,
62# no matter what other rules may be in play at the time.
63#
64# See rule LB 19 for an example.
65#
66
67# Temporary definitions of Emoji Base and Emoji Modifiers, until properties are available.
68
69$EB = [\u261D\u26F9\u270A-\u270D\U0001F385\U0001F3C2-\U0001F3C4\U0001F3C7\U0001F3CA-\U0001F3CC\U0001F442-\U0001F443\U0001F446-\U0001F450\U0001F466-\U0001F478\U0001F47C\U0001F481-\U0001F483\U0001F485-\U0001F487\U0001F4AA\U0001F574-\U0001F575\U0001F57A\U0001F590\U0001F595-\U0001F596\U0001F645-\U0001F647\U0001F64B-\U0001F64F\U0001F6A3\U0001F6B4-\U0001F6B6\U0001F6C0\U0001F6CC\U0001F918-\U0001F91E\U0001F926\U0001F930\U0001F933-\U0001F939\U0001F93C-\U0001F93E];
70$EM = [\U0001F3FB-\U0001F3FF];
71
72$AI = [[:LineBreak = Ambiguous:] - [\u2640\u2642]];
73$AL = [[:LineBreak = Alphabetic:] - [$EM\u2695\u2696\u2764]];
74$BA = [:LineBreak = Break_After:];
75$BB = [:LineBreak = Break_Before:];
76$BK = [:LineBreak = Mandatory_Break:];
77$B2 = [:LineBreak = Break_Both:];
78$CB = [:LineBreak = Contingent_Break:];
79$CJ = [:LineBreak = Conditional_Japanese_Starter:];
80$CL = [:LineBreak = Close_Punctuation:];
81$CM = [[:LineBreak = Combining_Mark:] \u200d];
82$CP = [:LineBreak = Close_Parenthesis:];
83$CR = [:LineBreak = Carriage_Return:];
84$EX = [:LineBreak = Exclamation:];
85$GL = [:LineBreak = Glue:];
86$HL = [:LineBreak = Hebrew_Letter:];
87$HY = [:LineBreak = Hyphen:];
88$H2 = [:LineBreak = H2:];
89$H3 = [:LineBreak = H3:];
90$ID = [[:LineBreak = Ideographic:] $CJ [\u2640\u2642\u2695\u2696\u2764] - $EB];
91$IN = [:LineBreak = Inseperable:];
92$IS = [:LineBreak = Infix_Numeric:];
93$JL = [:LineBreak = JL:];
94$JV = [:LineBreak = JV:];
95$JT = [:LineBreak = JT:];
96$LF = [:LineBreak = Line_Feed:];
97$NL = [:LineBreak = Next_Line:];
98$NS = [:LineBreak = Nonstarter:];
99$NU = [:LineBreak = Numeric:];
100$OP = [:LineBreak = Open_Punctuation:];
101$PO = [:LineBreak = Postfix_Numeric:];
102$PR = [:LineBreak = Prefix_Numeric:];
103$QU = [:LineBreak = Quotation:];
104$RI = [:LineBreak = Regional_Indicator:];
105$SA = [:LineBreak = Complex_Context:];
106$SG = [:LineBreak = Surrogate:];
107$SP = [:LineBreak = Space:];
108$SY = [:LineBreak = Break_Symbols:];
109$WJ = [:LineBreak = Word_Joiner:];
110$XX = [:LineBreak = Unknown:];
111$ZW = [:LineBreak = ZWSpace:];
112$ZWJ = [\u200d];
113
114# Dictionary character set, for triggering language-based break engines. Currently
115# limited to LineBreak=Complex_Context. Note that this set only works in Unicode
116# 5.0 or later as the definition of Complex_Context was corrected to include all
117# characters requiring dictionary break.
118
119$dictionary = [:LineBreak = Complex_Context:];
120
121#
122# Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
123# SA (South East Asian: Thai, Lao, Khmer)
124# SG (Unpaired Surrogates)
125# XX (Unknown, unassigned)
126# as $AL (Alphabetic)
127#
128$ALPlus = [$AL $AI $SA $SG $XX];
129
130#
131# Combining Marks. X $CM* behaves as if it were X. Rule LB6.
132#
133$ALcm = $ALPlus $CM*;
134$BAcm = $BA $CM*;
135$BBcm = $BB $CM*;
136$B2cm = $B2 $CM*;
137$CLcm = $CL $CM*;
138$CPcm = $CP $CM*;
139$EXcm = $EX $CM*;
140$GLcm = $GL $CM*;
141$HLcm = $HL $CM*;
142$HYcm = $HY $CM*;
143$H2cm = $H2 $CM*;
144$H3cm = $H3 $CM*;
145$INcm = $IN $CM*;
146$IScm = $IS $CM*;
147$JLcm = $JL $CM*;
148$JVcm = $JV $CM*;
149$JTcm = $JT $CM*;
150$NScm = $NS $CM*;
151$NUcm = $NU $CM*;
152$OPcm = $OP $CM*;
153$POcm = $PO $CM*;
154$PRcm = $PR $CM*;
155$QUcm = $QU $CM*;
156$RIcm = $RI $CM*;
157$SYcm = $SY $CM*;
158$WJcm = $WJ $CM*;
159
160## -------------------------------------------------
161
162!!forward;
163
164#
165# Each class of character can stand by itself as an unbroken token, with trailing combining stuff
166#
167$ALPlus $CM+;
168$BA $CM+;
169$BB $CM+;
170$B2 $CM+;
171$CL $CM+;
172$CP $CM+;
173$EB $CM+;
174$EM $CM+;
175$EX $CM+;
176$GL $CM+;
177$HL $CM+;
178$HY $CM+;
179$H2 $CM+;
180$H3 $CM+;
181$ID $CM+;
182$IN $CM+;
183$IS $CM+;
184$JL $CM+;
185$JV $CM+;
186$JT $CM+;
187$NS $CM+;
188$NU $CM+;
189$OP $CM+;
190$PO $CM+;
191$PR $CM+;
192$QU $CM+;
193$RI $CM+;
194$SY $CM+;
195$WJ $CM+;
196
197#
198# CAN_CM is the set of characters that may combine with CM combining chars.
199# Note that Linebreak UAX 14's concept of a combining char and the rules
200# for what they can combine with are _very_ different from the rest of Unicode.
201#
202# Note that $CM itself is left out of this set. If CM is needed as a base
203# it must be listed separately in the rule.
204#
205$CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs
206$CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs
207
208#
209# AL_FOLLOW set of chars that can unconditionally follow an AL
210# Needed in rules where stand-alone $CM s are treated as AL.
211# Chaining is disabled with CM because it causes other failures,
212# so for this one case we need to manually list out longer sequences.
213#
214$AL_FOLLOW_NOCM = [$BK $CR $LF $NL $ZW $SP];
215$AL_FOLLOW_CM = [$CL $CP $EX $HL $IS $SY $WJ $GL $OP $QU $BA $HY $NS $IN $NU $ALPlus];
216$AL_FOLLOW = [$AL_FOLLOW_NOCM $AL_FOLLOW_CM];
217
218
219#
220# Rule LB 4, 5 Mandatory (Hard) breaks.
221#
222$LB4Breaks = [$BK $CR $LF $NL];
223$LB4NonBreaks = [^$BK $CR $LF $NL $CM];
224$CR $LF {100};
225
226#
227# LB 6 Do not break before hard line breaks.
228#
229$LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
230$CAN_CM $CM* $LB4Breaks {100};
231^$CM+ $LB4Breaks {100};
232
233# LB 7 x SP
234# x ZW
235$LB4NonBreaks [$SP $ZW];
236$CAN_CM $CM* [$SP $ZW];
237^$CM+ [$SP $ZW];
238
239#
240# LB 8 Break after zero width space
241# TODO: ZW SP* <break>
242# An engine change is required to write the reverse rule for this.
243# For now, leave the Unicode 5.2 rule, ZW <break>
244#
245$LB8Breaks = [$LB4Breaks $ZW];
246$LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
247
248# LB 8a ZWJ x ID Emoji proposal.
249#
250$ZWJ ($ID | $EB | $EM);
251
252# LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
253# $CM not covered by the above needs to behave like $AL
254# See definition of $CAN_CM.
255
256$CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
257^$CM+;
258
259#
260# LB 11 Do not break before or after WORD JOINER & related characters.
261#
262$CAN_CM $CM* $WJcm;
263$LB8NonBreaks $WJcm;
264^$CM+ $WJcm;
265
266$WJcm $CANT_CM;
267$WJcm $CAN_CM $CM*;
268
269#
270# LB 12 Do not break after NBSP and related characters.
271# GL x
272#
273$GLcm $CAN_CM $CM*;
274$GLcm $CANT_CM;
275
276#
277# LB 12a Do not break before NBSP and related characters ...
278# [^SP BA HY] x GL
279#
280[[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GLcm;
281^$CM+ $GLcm;
282
283
284
285#
286# LB 13 Don't break before ']' or '!' or ';' or '/', even after spaces.
287#
288$LB8NonBreaks $CL;
289$CAN_CM $CM* $CL;
290^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
291
292$LB8NonBreaks $CP;
293$CAN_CM $CM* $CP;
294^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
295
296$LB8NonBreaks $EX;
297$CAN_CM $CM* $EX;
298^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
299
300$LB8NonBreaks $IS;
301$CAN_CM $CM* $IS;
302^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
303
304$LB8NonBreaks $SY;
305$CAN_CM $CM* $SY;
306^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
307
308
309#
310# LB 14 Do not break after OP, even after spaces
311#
312$OPcm $SP* $CAN_CM $CM*;
313$OPcm $SP* $CANT_CM;
314
315$OPcm $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
316
317# LB 15
318$QUcm $SP* $OPcm;
319
320# LB 16
321($CLcm | $CPcm) $SP* $NScm;
322
323# LB 17
324$B2cm $SP* $B2cm;
325
326#
327# LB 18 Break after spaces.
328#
329$LB18NonBreaks = [$LB8NonBreaks - [$SP]];
330$LB18Breaks = [$LB8Breaks $SP];
331
332
333# LB 19
334# x QU
335$LB18NonBreaks $CM* $QUcm;
336^$CM+ $QUcm;
337
338# QU x
339$QUcm .?;
340
341
342# LB 20
343# <break> $CB
344# $CB <break>
345
346$LB20NonBreaks = [$LB18NonBreaks - $CB];
347
348# LB 21 x (BA | HY | NS)
349# BB x
350#
351$LB20NonBreaks $CM* ($BAcm | $HYcm | $NScm);
352^$CM+ ($BAcm | $HYcm | $NScm);
353
354$BBcm [^$CB]; # $BB x
355$BBcm $LB20NonBreaks $CM*;
356
357# LB 21a Don't break after Hebrew + Hyphen
358# HL (HY | BA) x
359#
360$HLcm ($HYcm | $BAcm) [^$CB]?;
361
362# LB 21b (forward) Don't break between SY and HL
363# (break between HL and SY already disallowed by LB 13 above)
364$SYcm $HLcm;
365
366# LB 22
367($ALcm | $HLcm) $INcm;
368^$CM+ $INcm; # by rule 10, any otherwise unattached CM behaves as AL
369$EXcm $INcm;
370($ID | $EB | $EM) $CM* $INcm;
371$INcm $INcm;
372$NUcm $INcm;
373
374
375# $LB 23
376($ID | $EB | $EM) $CM* $POcm;
377$ALcm $NUcm; # includes $LB19
378$HLcm $NUcm;
379^$CM+ $NUcm; # Rule 10, any otherwise unattached CM behaves as AL
380$NUcm $ALcm;
381$NUcm $HLcm;
382
383#
384# LB 24
385#
386$PRcm ($ID | $EB | $EM);
387$PRcm ($ALcm | $HLcm);
388$POcm ($ALcm | $HLcm);
389($ALcm | $HLcm) ($PRcm | $POcm);
390^$CM+ ($PRcm | $POcm); # Rule 10, any otherwise unattached CM behaves as AL
391
392#
393# LB 25 Numbers.
394#
395($PRcm | $POcm)? ($OPcm | $HYcm)? $NUcm ($NUcm | $SYcm | $IScm)* ($CLcm | $CPcm)? ($PRcm | $POcm)?;
396
397# LB 26 Do not break a Korean syllable
398#
399$JLcm ($JLcm | $JVcm | $H2cm | $H3cm);
400($JVcm | $H2cm) ($JVcm | $JTcm);
401($JTcm | $H3cm) $JTcm;
402
403# LB 27 Treat korean Syllable Block the same as ID (don't break it)
404($JLcm | $JVcm | $JTcm | $H2cm | $H3cm) $INcm;
405($JLcm | $JVcm | $JTcm | $H2cm | $H3cm) $POcm;
406$PRcm ($JLcm | $JVcm | $JTcm | $H2cm | $H3cm);
407
408
409# LB 28 Do not break between alphabetics
410#
411($ALcm | $HLcm) ($ALcm | $HLcm);
412^$CM+ ($ALcm | $HLcm); # The $CM+ is from rule 10, an unattached CM is treated as AL
413
414# LB 29
415$IScm ($ALcm | $HLcm);
416
417# LB 30
418($ALcm | $HLcm | $NUcm) $OPcm;
419^$CM+ $OPcm; # The $CM+ is from rule 10, an unattached CM is treated as AL.
420$CPcm ($ALcm | $HLcm | $NUcm);
421
422# LB 30a Do not break between regional indicators. Break after pairs of them.
423# Tricky interaction with LB8a: ZWJ x ID
424$RIcm $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM] {eof}];
425$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}];
426$RIcm $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM] {eof}];
427
428$RIcm $RIcm [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS {eof}];
429$RIcm $RIcm $ZWJ ($ID | $EB | $EM);
430
431# LB 30b Do not break between an Emoji Base and an Emoji Modifier
432$EB $CM* $EM;
433
434#
435# Reverse Rules.
436#
437## -------------------------------------------------
438
439!!reverse;
440
441^$CM+ $ALPlus;
442^$CM+ $BA;
443^$CM+ $BB;
444^$CM+ $B2;
445^$CM+ $CL;
446^$CM+ $CP;
447^$CM+ $EB;
448^$CM+ $EM;
449^$CM+ $EX;
450^$CM+ $GL;
451^$CM+ $HL;
452^$CM+ $HY;
453^$CM+ $H2;
454^$CM+ $H3;
455^$CM+ $ID;
456^$CM+ $IN;
457^$CM+ $IS;
458^$CM+ $JL;
459^$CM+ $JV;
460^$CM+ $JT;
461^$CM+ $NS;
462^$CM+ $NU;
463^$CM+ $OP;
464^$CM+ $PO;
465^$CM+ $PR;
466^$CM+ $QU;
467^$CM+ $RI;
468^$CM+ $SY;
469^$CM+ $WJ;
470^$CM+;
471
472
473#
474# Sequences of the form (shown forwards)
475# [CANT_CM] <break> [CM] [whatever]
476# The CM needs to behave as an AL
477#
478$AL_FOLLOW $CM+ / (
479 [$BK $CR $LF $NL $ZW {eof}] |
480 $SP+ $CM+ $SP |
481 $SP+ $CM* ([^$OP $CM $SP] | [$AL {eof}])); # if LB 14 will match, need to surpress this break.
482 # LB14 says OP SP* x .
483 # becomes OP SP* x AL
484 # becomes OP SP* x CM+ AL_FOLLOW
485 #
486 # Further note: the $AL in [$AL {eof}] is only to work around
487 # a rule compiler bug which complains about
488 # empty sets otherwise.
489
490#
491# Sequences of the form (shown forwards)
492# [CANT_CM] <break> [CM] <break> [PR]
493# The CM needs to behave as an AL
494# This rule is concerned about getting the second of the two <breaks> in place.
495#
496
497# Apple early addition, remove this, superseded by LB24
498# [$PR ] / $CM+ [$BK $CR $LF $NL $ZW $SP {eof}];
499
500
501
502# LB 4, 5, 6
503
504$LB4Breaks [$LB4NonBreaks-$CM];
505$LB4Breaks $CM+ $CAN_CM;
506$LF $CR;
507
508
509# LB 7 x SP
510# x ZW
511[$SP $ZW] [$LB4NonBreaks-$CM];
512[$SP $ZW] $CM+ $CAN_CM;
513
514# LB 8 ZW SP* <break>
515# TODO: to implement this, we need more than one look-ahead hard break in play at a time.
516# Requires an engine enhancement.
517# / $SP* $ZW
518
519# LB 8a ZWJ x ID Unicode Emoji proposal L2/16-011R3
520# The ZWJ will look like a CM to whatever precedes it.
521#
522($ID | $EB | $EM) $ZWJ $CM* $CAN_CM?;
523
524
525# LB 9,10 Combining marks.
526# X $CM needs to behave like X, where X is not $SP or controls.
527# $CM not covered by the above needs to behave like $AL
528# Stick together any combining sequences that don't match other rules.
529^$CM+ $CAN_CM;
530
531
532# LB 11
533#
534$WJ $CM* $CAN_CM;
535$WJ [$LB8NonBreaks-$CM];
536
537 $CANT_CM $CM* $WJ;
538$CAN_CM $CM* $WJ;
539
540# LB 12a
541# [^SP BA HY] x GL
542#
543$GL $CM* [$LB8NonBreaks-[$CM $SP $BA $HY]];
544
545# LB 12
546# GL x
547#
548$CANT_CM $CM* $GL;
549$CAN_CM $CM* $GL;
550
551
552# LB 13
553$CL $CM+ $CAN_CM;
554$CP $CM+ $CAN_CM;
555$EX $CM+ $CAN_CM;
556$IS $CM+ $CAN_CM;
557$SY $CM+ $CAN_CM;
558
559$CL [$LB8NonBreaks-$CM];
560$CP [$LB8NonBreaks-$CM];
561$EX [$LB8NonBreaks-$CM];
562$IS [$LB8NonBreaks-$CM];
563$SY [$LB8NonBreaks-$CM];
564
565# Rule 13 & 14 taken together for an edge case.
566# Match this, shown forward
567# OP SP+ ($CM+ behaving as $AL) (CL | CP | EX | IS | IY)
568# This really wants to chain at the $CM+ (which is acting as an $AL)
569# except for $CM chaining being disabled.
570[$CL $CP $EX $IS $SY] $CM+ $SP+ $CM* $OP;
571
572# LB 14 OP SP* x
573#
574$CAN_CM $SP* $CM* $OP;
575 $CANT_CM $SP* $CM* $OP;
576$AL_FOLLOW? $CM+ $SP $SP* $CM* $OP; # by LB 10, behaves like $AL_FOLLOW? $AL $SP* $CM* $OP
577
578 $AL_FOLLOW_NOCM $CM+ $SP+ $CM* $OP;
579$AL_FOLLOW_CM $CM+ $SP+ $CM* $OP;
580
581
582# LB 15
583$OP $SP* $CM* $QU;
584
585# LB 16
586$NS $SP* $CM* ($CL | $CP);
587
588# LB 17
589$B2 $SP* $CM* $B2;
590
591# LB 18 break after spaces
592# Nothing explicit needed here.
593
594
595#
596# LB 19
597#
598$QU $CM* $CAN_CM; # . x QU
599$QU $LB18NonBreaks;
600
601
602$CAN_CM $CM* $QU; # QU x .
603 $CANT_CM $CM* $QU;
604
605#
606# LB 20 Break before and after CB.
607# nothing needed here.
608#
609
610# LB 21
611($BA | $HY | $NS) $CM* [$LB20NonBreaks-$CM]; # . x (BA | HY | NS)
612
613[$LB20NonBreaks-$CM] $CM* $BB; # BB x .
614[^$CB] $CM* $BB; #
615
616# LB21a
617[^$CB] $CM* ($HY | $BA) $CM* $HL;
618
619# LB21b (reverse)
620$HL $CM* $SY;
621
622# LB 22
623$IN $CM* ($ALPlus | $HL);
624$IN $CM* $EX;
625$IN $CM* ($ID | $EB | $EM);
626$IN $CM* $IN;
627$IN $CM* $NU;
628
629# LB 23
630$PO $CM* ($ID | $EB | $EM);
631$NU $CM* ($ALPlus | $HL);
632($ALPlus | $HL) $CM* $NU;
633
634# LB 24
635($ID | $EB | $EM) $CM* $PR;
636($ALPlus | $HL) $CM* $PR;
637($ALPlus | $HL) $CM* $PO;
638$CM* ($PR | $PO) $CM* ($ALPlus | $HL);
639$CM* ($PR | $PO) $CM+ / [$BK $CR $LF $NL $ZW $SP {eof}];
640
641# LB 25
642($CM* ($PR | $PO))? ($CM* ($CL | $CP))? ($CM* ($NU | $IS | $SY))* $CM* $NU ($CM* ($OP | $HY))? ($CM* ($PR | $PO))?;
643
644# LB 26
645($H3 | $H2 | $JV | $JL) $CM* $JL;
646($JT | $JV) $CM* ($H2 | $JV);
647$JT $CM* ($H3 | $JT);
648
649# LB 27
650$IN $CM* ($H3 | $H2 | $JT | $JV | $JL);
651$PO $CM* ($H3 | $H2 | $JT | $JV | $JL);
652 ($H3 | $H2 | $JT | $JV | $JL) $CM* $PR;
653
654# LB 28
655($ALPlus | $HL) $CM* ($ALPlus | $HL);
656
657
658# LB 29
659($ALPlus | $HL) $CM* $IS;
660
661# LB 30
662$OP $CM* ($ALPlus | $HL | $NU);
663($ALPlus | $HL | $NU) $CM* $CP;
664
665# LB 30a
666# Pairs of Regional Indicators.
667# The following two rules are nearly identical. The first matches only sequences with an odd number of adjacent RIs,
668# the second with an even number. Stripping away the cruft they look like
669# [^RI] RI / (RI RI)+ ^RI;
670# [^RI] RI RI / (RI RI)+ ^RI;
671#
672[{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]];
673[{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]];
674
675# In general, adjacent RIs stay together. The hard-break rules, above, overide this, forcing in the boundaries between pairs.
676$RI $CM* $RI;
677
678# WJ, GL, QU, etc. are classes with rules like "WJ x " which includes "WJ x RI".
679$RI $CM* ([$WJ $GL $QU $BB] | (($HY | $BA)$CM* $HL));
680
681
682# LB 30b Do not break between an Emoji Base and an Emoji Modifier
683$EM $CM* $EB;
684
685
686## -------------------------------------------------
687
688!!safe_reverse;
689
690# LB 9
691^$CM+ [^$CM $BK $CR $LF $NL $ZW $SP];
692^$CM+ $SP / .;
693
694# LB 14
695$SP+ $CM* $OP;
696
697# LB 15
698$SP+ $CM* $QU;
699
700# LB 16
701$SP+ $CM* ($CL | $CP);
702
703# LB 17
704$SP+ $CM* $B2;
705
706# LB 21
707$CM* ($HY | $BA) $CM* $HL;
708
709# LB 25
710($CM* ($IS | $SY))+ $CM* $NU;
711($CL | $CP) $CM* ($NU | $IS | $SY);
712
713# LB 30
714($CM* $RI)+;
715
716# For dictionary-based break
717$dictionary $dictionary;
718
719## -------------------------------------------------
720
721!!safe_forward;
722
723# Skip forward over all character classes that are involved in
724# rules containing patterns with possibly more than one char
725# of context.
726#
727# It might be slightly more efficient to have specific rules
728# instead of one generic one, but only if we could
729# turn off rule chaining. We don't want to move more
730# than necessary.
731#
732^[$CM $OP $QU $CL $CP $B2 $PR $HY $BA $SP $RI $ZWJ $dictionary]+ [^$CM $OP $QU $CL $CP $B2 $PR $HY $BA $RI $ZWJ $dictionary];
733$dictionary $dictionary;
734