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