#
# Line Breaking Rules
# Implement default line breaking as defined by
-# Unicode Standard Annex #14 Revision 40 for Unicode 11.0
-# http://www.unicode.org/reports/tr14/
+# Unicode Standard Annex #14 Revision 44 for Unicode 13.0
+# http://www.unicode.org/reports/tr14/, with the following modification:
#
-# TODO: Rule LB 8 remains as it was in Unicode 5.2
-# This is only because of a limitation of ICU break engine implementation,
-# not because the older behavior is desirable.
+# Boundaries between hyphens and following letters are suppressed when
+# there is a boundary preceding the hyphen. See rule 20.9
#
# This corresponds to CSS line-break=strict (BCP47 -u-lb-strict).
# It sets characters of class CJ to behave like NS.
$AI = [:LineBreak = Ambiguous:];
$AL = [:LineBreak = Alphabetic:];
$BA = [:LineBreak = Break_After:];
+$HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA.
$BB = [:LineBreak = Break_Before:];
$BK = [:LineBreak = Mandatory_Break:];
$B2 = [:LineBreak = Break_Both:];
# $CM = [:LineBreak = Combining_Mark:];
$CP = [:LineBreak = Close_Parenthesis:];
$CR = [:LineBreak = Carriage_Return:];
-$EB = [[:LineBreak = EB:] \U0001F46A-\U0001F46D\U0001F46F\U0001F91D\U0001F93C];
+$EB = [:LineBreak = EB:];
$EM = [:LineBreak = EM:];
$EX = [:LineBreak = Exclamation:];
$GL = [:LineBreak = Glue:];
# $EmojiNRK = [[\p{Emoji}] - [$RI \u002a\u00230-9©®™〰〽]];
# $Extended_Pict = [:ExtPict:];
+# OP30 and CP30 are variants of OP and CP that appear in-line in rule LB30 from UAX 14,
+# without a formal name. Because ICU rules require multiple uses of the expressions,
+# give them a single definition with a name
+
+$OP30 = [$OP - [\p{ea=F}\p{ea=W}\p{ea=H}]];
+$CP30 = [$CP - [\p{ea=F}\p{ea=W}\p{ea=H}]];
+
# By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly
# list it in the numerous rules that use CM.
# By LB1, SA characters with general categor of Mn or Mc also resolve to CM.
$CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]];
+$CMX = [[$CM] - [$ZWJ]];
# Dictionary character set, for triggering language-based break engines. Currently
# limited to LineBreak=Complex_Context (SA).
# AL_FOLLOW set of chars that can unconditionally follow an AL
# Needed in rules where stand-alone $CM s are treated as AL.
#
-$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];
+$AL_FOLLOW = [$BK $CR $LF $NL $ZW $SP $CL $CP $EX $HL $IS $SY $WJ $GL $OP30 $QU $BA $HY $NS $IN $NU $PR $PO $ALPlus];
#
#
# LB 8 Break after zero width space
-# TODO: ZW SP* <break>
-# An engine change is required to write the reverse rule for this.
-# For now, leave the Unicode 5.2 rule, ZW <break>
+# ZW SP* ÷
#
$LB8Breaks = [$LB4Breaks $ZW];
$LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
+$ZW $SP* / [^$SP $ZW $LB4Breaks];
# LB 8a ZWJ x Do not break Emoji ZWJ sequences.
#
-#
-# LB 13 Don't break before ']' or '!' or ';' or '/', even after spaces.
+
+# LB 13 Don't break before ']' or '!' or or '/', even after spaces.
#
$LB8NonBreaks $CL;
$CAN_CM $CM* $CL;
$CAN_CM $CM* $EX;
^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
-$LB8NonBreaks $IS;
-$CAN_CM $CM* $IS;
-^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
-
$LB8NonBreaks $SY;
$CAN_CM $CM* $SY;
^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
#
# LB 14 Do not break after OP, even after spaces
+# Note subtle interaction with "SP IS /" rules in LB14a.
+# This rule consumes the SP, chaining happens on the IS, effectivley overriding the SP IS rules,
+# which is the desired behavior.
#
$OP $CM* $SP* .;
$OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
# by rule 8, CM following a SP is stand-alone.
+
+# LB 14a Force a break before start of a number with a leading decimal pt, e.g. " .23"
+# Note: would be simpler to express as "$SP / $IS $CM* $NU;", but ICU rules have limitations.
+# See issue ICU-20303
+
+
+$CanFollowIS = [$BK $CR $LF $NL $SP $ZW $WJ $GL $CL $CP $EX $IS $SY $QU $BA $HY $NS $ALPlus $HL $IN];
+$SP $IS / [^ $CanFollowIS $NU $CM];
+$SP $IS $CM* $CMX / [^ $CanFollowIS $NU $CM];
+
+#
+# LB 14b Do not break before numeric separators (IS), even after spaces.
+
+[$LB8NonBreaks - $SP] $IS;
+$SP $IS $CM* [$CanFollowIS {eof}];
+$SP $IS $CM* $ZWJ [^$CM $NU];
+
+$CAN_CM $CM* $IS;
+^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
+
+
# LB 15
$QU $CM* $SP* $OP;
# QU x
$QU $CM* .;
-
# LB 20
# <break> $CB
# $CB <break>
-
+#
$LB20NonBreaks = [$LB18NonBreaks - $CB];
+# LB 20.09 Don't break between Hyphens and Letters when there is a break preceding the hyphen.
+# Originally added as a Finnish tailoring, now promoted to default ICU behavior.
+# Note: this is not default UAX-14 behaviour. See issue ICU-8151.
+#
+^($HY | $HH) $CM* $ALPlus;
+
# LB 21 x (BA | HY | NS)
# BB x
#
$LB20NonBreaks $CM* ($BA | $HY | $NS);
+
+
^$CM+ ($BA | $HY | $NS);
$BB $CM* [^$CB]; # $BB x
# (break between HL and SY already disallowed by LB 13 above)
$SY $CM* $HL;
-# LB 22
-($ALPlus | $HL) $CM* $IN;
-^$CM+ $IN; # by rule 10, any otherwise unattached CM behaves as AL
-$EX $CM* $IN;
-($ID | $EB | $EM) $CM* $IN;
-$IN $CM* $IN;
-$NU $CM* $IN;
+# LB 22 Do not break before ellipses
+#
+$LB20NonBreaks $CM* $IN;
+^$CM+ $IN;
-# $LB 23
+# LB 23
#
($ALPlus | $HL) $CM* $NU;
^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL
#
# LB 25 Numbers.
#
-(($PR | $PO) $CM*)? (($OP | $HY) $CM*)? $NU ($CM* ($NU | $SY | $IS))*
+(($PR | $PO) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))*
($CM* ($CL | $CP))? ($CM* ($PR | $PO))?;
# LB 26 Do not break a Korean syllable
$IS $CM* ($ALPlus | $HL);
# LB 30
-($ALPlus | $HL | $NU) $CM* $OP;
-^$CM+ $OP; # The $CM+ is from rule 10, an unattached CM is treated as AL.
-$CP $CM* ($ALPlus | $HL | $NU);
+($ALPlus | $HL | $NU) $CM* $OP30;
+^$CM+ $OP30; # The $CM+ is from rule 10, an unattached CM is treated as AL.
+$CP30 $CM* ($ALPlus | $HL | $NU);
# LB 30a Do not break between regional indicators. Break after pairs of them.
# Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM.
-$RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
-$RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
-$RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $ZWJ {eof}];
+$RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $CM]];
+$RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $CM]];
+$RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $ZWJ {eof}];
# note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?'
# because of the chain-out behavior difference. The rule must chain out only from the [set characters],
# not from the preceding $RI or $CM, which it would be able to do if the set were optional.