-# Copyright (c) 2002-2008 International Business Machines Corporation and
+# Copyright (c) 2002-2015 International Business Machines Corporation and
# others. All Rights Reserved.
#
# file: line.txt
#
# Line Breaking Rules
# Implement default line breaking as defined by
-# Unicode Standard Annex #14 Revision 21 for Unicode 5.1
+# Unicode Standard Annex #14 Revision 29 for Unicode 6.2
# http://www.unicode.org/reports/tr14/
-
-
+#
+# 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.
+#
+# This corresponds to CSS line-break=strict (BCP47 -u-lb-strict).
+# It sets characters of class CJ to behave like NS.
#
# Character Classes defined by TR 14.
# !!lookAheadHardBreak Described here because it is (as yet) undocumented elsewhere
# and only used for the line break rules.
#
-# It is used in the implementation of the incredibly annoying rule LB 10
+# It is used in the implementation of rule LB 10
# which says to treat any combining mark that is not attached to a base
# character as if it were of class AL (alphabetic).
#
$BK = [:LineBreak = Mandatory_Break:];
$B2 = [:LineBreak = Break_Both:];
$CB = [:LineBreak = Contingent_Break:];
+$CJ = [:LineBreak = Conditional_Japanese_Starter:];
$CL = [:LineBreak = Close_Punctuation:];
$CM = [:LineBreak = Combining_Mark:];
+$CP = [:LineBreak = Close_Parenthesis:];
$CR = [:LineBreak = Carriage_Return:];
$EX = [:LineBreak = Exclamation:];
$GL = [:LineBreak = Glue:];
+$HL = [:LineBreak = Hebrew_Letter:];
$HY = [:LineBreak = Hyphen:];
$H2 = [:LineBreak = H2:];
$H3 = [:LineBreak = H3:];
$JT = [:LineBreak = JT:];
$LF = [:LineBreak = Line_Feed:];
$NL = [:LineBreak = Next_Line:];
-$NS = [:LineBreak = Nonstarter:];
+$NS = [[:LineBreak = Nonstarter:] $CJ];
$NU = [:LineBreak = Numeric:];
$OP = [:LineBreak = Open_Punctuation:];
$PO = [:LineBreak = Postfix_Numeric:];
$PR = [:LineBreak = Prefix_Numeric:];
$QU = [:LineBreak = Quotation:];
+$RI = [:LineBreak = Regional_Indicator:];
$SA = [:LineBreak = Complex_Context:];
$SG = [:LineBreak = Surrogate:];
$SP = [:LineBreak = Space:];
$XX = [:LineBreak = Unknown:];
$ZW = [:LineBreak = ZWSpace:];
+# Special character classes for people & body part emoji:
+# Subsets of $CM:
+$ZWJ = \u200D;
+$EmojiVar = \uFE0F;
+# The following are subsets of $ID
+$EmojiForSeqs = [\u2764 \U0001F441 \U0001F466-\U0001F469 \U0001F48B \U0001F5E8];
+$EmojiForMods = [\u261D \u26F9 \u270A-\u270D \U0001F385 \U0001F3C3-\U0001F3C4 \U0001F3C7 \U0001F3CA-\U0001F3CB \U0001F442-\U0001F443 \U0001F446-\U0001F450 \U0001F466-\U0001F469 \U0001F46E-\U0001F478 \U0001F47C \U0001F481-\U0001F483 \U0001F485-\U0001F487 \U0001F4AA \U0001F590 \U0001F595 \U0001F596 \U0001F645-\U0001F647 \U0001F64B-\U0001F64F \U0001F6A3 \U0001F6B4-\U0001F6B6 \U0001F6C0 \U0001F918];
+$EmojiMods = [\U0001F3FB-\U0001F3FF];
+
# Dictionary character set, for triggering language-based break engines. Currently
# limited to LineBreak=Complex_Context. Note that this set only works in Unicode
# 5.0 or later as the definition of Complex_Context was corrected to include all
$BBcm = $BB $CM*;
$B2cm = $B2 $CM*;
$CLcm = $CL $CM*;
+$CPcm = $CP $CM*;
$EXcm = $EX $CM*;
$GLcm = $GL $CM*;
+$HLcm = $HL $CM*;
$HYcm = $HY $CM*;
$H2cm = $H2 $CM*;
$H3cm = $H3 $CM*;
$POcm = $PO $CM*;
$PRcm = $PR $CM*;
$QUcm = $QU $CM*;
+$RIcm = $RI $CM*;
$SYcm = $SY $CM*;
$WJcm = $WJ $CM*;
$BB $CM+;
$B2 $CM+;
$CL $CM+;
+$CP $CM+;
$EX $CM+;
$GL $CM+;
+$HL $CM+;
$HY $CM+;
$H2 $CM+;
$H3 $CM+;
$PO $CM+;
$PR $CM+;
$QU $CM+;
+$RI $CM+;
$SY $CM+;
$WJ $CM+;
# so for this one case we need to manually list out longer sequences.
#
$AL_FOLLOW_NOCM = [$BK $CR $LF $NL $ZW $SP];
-$AL_FOLLOW_CM = [$CL $EX $IS $SY $WJ $GL $QU $BA $HY $NS $IN $NU $ALPlus];
+$AL_FOLLOW_CM = [$CL $CP $EX $HL $IS $SY $WJ $GL $OP $QU $BA $HY $NS $IN $NU $ALPlus];
$AL_FOLLOW = [$AL_FOLLOW_NOCM $AL_FOLLOW_CM];
#
# 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>
#
$LB8Breaks = [$LB4Breaks $ZW];
$LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
+# Special forward rule for people & body part emoji:
+# don't break $ZWJ from subsequent $EmojiForSeqs
+$EmojiForSeqs $EmojiVar? $EmojiMods? $ZWJ $EmojiForSeqs;
+
# LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
# $CM not covered by the above needs to behave like $AL
# See definition of $CAN_CM.
$CAN_CM $CM* $CL;
$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
+$LB8NonBreaks $CP;
+$CAN_CM $CM* $CP;
+$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
+
$LB8NonBreaks $EX;
$CAN_CM $CM* $EX;
$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
$QUcm $SP* $OPcm;
# LB 16
-$CLcm $SP* $NScm;
+($CLcm | $CPcm) $SP* $NScm;
# LB 17
$B2cm $SP* $B2cm;
$BBcm [^$CB]; # $BB x
$BBcm $LB20NonBreaks $CM*;
+# LB 21a Don't break after Hebrew + Hyphen
+# HL (HY | BA) x
+#
+$HLcm ($HYcm | $BAcm) [^$CB]?;
+
+# LB 21b (forward) Don't break between SY and HL
+# (break between HL and SY already disallowed by LB 13 above)
+$SYcm $HLcm;
+
# LB 22
-$ALcm $INcm;
+($ALcm | $HLcm) $INcm;
$CM+ $INcm; # by rule 10, any otherwise unattached CM behaves as AL
$IDcm $INcm;
$INcm $INcm;
# $LB 23
$IDcm $POcm;
$ALcm $NUcm; # includes $LB19
+$HLcm $NUcm;
$CM+ $NUcm; # Rule 10, any otherwise unattached CM behaves as AL
$NUcm $ALcm;
+$NUcm $HLcm;
#
# LB 24
#
$PRcm $IDcm;
-$PRcm $ALcm;
-$POcm $ALcm;
+$PRcm ($ALcm | $HLcm);
+$POcm ($ALcm | $HLcm);
#
# LB 25 Numbers.
#
-($PRcm | $POcm)? ($OPcm | $HYcm)? $NUcm ($NUcm | $SYcm | $IScm)* $CLcm? ($PRcm | $POcm)?;
+($PRcm | $POcm)? ($OPcm | $HYcm)? $NUcm ($NUcm | $SYcm | $IScm)* ($CLcm | $CPcm)? ($PRcm | $POcm)?;
# LB 26 Do not break a Korean syllable
#
# LB 28 Do not break between alphabetics
#
-$ALcm $ALcm;
-$CM+ $ALcm; # The $CM+ is from rule 10, and unattached CM is treated as AL
+($ALcm | $HLcm) ($ALcm | $HLcm);
+$CM+ ($ALcm | $HLcm); # The $CM+ is from rule 10, an unattached CM is treated as AL
# LB 29
-$IScm $ALcm;
+$IScm ($ALcm | $HLcm);
+
+# LB 30
+($ALcm | $HLcm | $NUcm) $OPcm;
+$CM+ $OPcm; # The $CM+ is from rule 10, an unattached CM is treated as AL.
+$CPcm ($ALcm | $HLcm | $NUcm);
+# LB 30a Do not break between regional indicators.
+$RIcm $RIcm;
+
+# Special forward rule for people & body part emoji:
+# don't break between relevant emoji and $EmojiMods
+$EmojiForMods $EmojiVar? $EmojiMods;
#
# Reverse Rules.
$CM+ $BB;
$CM+ $B2;
$CM+ $CL;
+$CM+ $CP;
$CM+ $EX;
$CM+ $GL;
+$CM+ $HL;
$CM+ $HY;
$CM+ $H2;
$CM+ $H3;
$CM+ $PO;
$CM+ $PR;
$CM+ $QU;
+$CM+ $RI;
$CM+ $SY;
$CM+ $WJ;
$CM+;
[$SP $ZW] [$LB4NonBreaks-$CM];
[$SP $ZW] $CM+ $CAN_CM;
-# LB 8 Break after zero width space
+# LB 8 ZW SP* <break>
+# TODO: to implement this, we need more than one look-ahead hard break in play at a time.
+# Requires an engine enhancement.
+# / $SP* $ZW
+# Special reverse rule for people & body part emoji:
+# don't break $ZWJ from subsequent $EmojiForSeqs
+$EmojiForSeqs $ZWJ $EmojiMods? $EmojiVar? $EmojiForSeqs;
# LB 9,10 Combining marks.
# X $CM needs to behave like X, where X is not $SP or controls.
# LB 13
$CL $CM+ $CAN_CM;
+$CP $CM+ $CAN_CM;
$EX $CM+ $CAN_CM;
$IS $CM+ $CAN_CM;
$SY $CM+ $CAN_CM;
$CL [$LB8NonBreaks-$CM];
+$CP [$LB8NonBreaks-$CM];
$EX [$LB8NonBreaks-$CM];
$IS [$LB8NonBreaks-$CM];
$SY [$LB8NonBreaks-$CM];
# Rule 13 & 14 taken together for an edge case.
# Match this, shown forward
-# OP SP+ ($CM+ behaving as $AL) (CL | EX | IS | IY)
+# OP SP+ ($CM+ behaving as $AL) (CL | CP | EX | IS | IY)
# This really wants to chain at the $CM+ (which is acting as an $AL)
# except for $CM chaining being disabled.
-[$CL $EX $IS $SY] $CM+ $SP+ $CM* $OP;
+[$CL $CP $EX $IS $SY] $CM+ $SP+ $CM* $OP;
# LB 14 OP SP* x
#
$CM* $OP $SP* $CM* $QU;
# LB 16
-$CM* $NS $SP* $CM* $CL;
+$CM* $NS $SP* $CM* ($CL | $CP);
# LB 17
$CM* $B2 $SP* $CM* $B2;
$CM* [$LB20NonBreaks-$CM] $CM* $BB; # BB x .
[^$CB] $CM* $BB; #
+# LB21a
+[^$CB] $CM* ($HY | $BA) $CM* $HL;
+# LB21b (reverse)
+$CM* $HL $CM* $SY;
# LB 22
-$CM* $IN $CM* $ALPlus;
+$CM* $IN $CM* ($ALPlus | $HL);
$CM* $IN $CM* $ID;
$CM* $IN $CM* $IN;
$CM* $IN $CM* $NU;
# LB 23
$CM* $PO $CM* $ID;
-$CM* $NU $CM* $ALPlus;
-$CM* $ALPlus $CM* $NU;
+$CM* $NU $CM* ($ALPlus | $HL);
+$CM* ($ALPlus | $HL) $CM* $NU;
# LB 24
$CM* $ID $CM* $PR;
-$CM* $ALPlus $CM* $PR;
-$CM* $ALPlus $CM* $PO;
+$CM* ($ALPlus | $HL) $CM* $PR;
+$CM* ($ALPlus | $HL) $CM* $PO;
# LB 25
-($CM* ($PR | $PO))? ($CM* $CL)? ($CM* ($NU | $IS | $SY))* $CM* $NU ($CM* ($OP | $HY))? ($CM* ($PR | $PO))?;
+($CM* ($PR | $PO))? ($CM* ($CL | $CP))? ($CM* ($NU | $IS | $SY))* $CM* $NU ($CM* ($OP | $HY))? ($CM* ($PR | $PO))?;
# LB 26
$CM* ($H3 | $H2 | $JV | $JL) $CM* $JL;
$CM* ($H3 | $H2 | $JT | $JV | $JL) $CM* $PR;
# LB 28
-$CM* $ALPlus $CM* $ALPlus;
+$CM* ($ALPlus | $HL) $CM* ($ALPlus | $HL);
# LB 29
-$CM* $ALPlus $CM* $IS;
+$CM* ($ALPlus | $HL) $CM* $IS;
+
+# LB 30
+$CM* $OP $CM* ($ALPlus | $HL | $NU);
+$CM* ($ALPlus | $HL | $NU) $CM* $CP;
+# LB 30a
+$CM* $RI $CM* $RI;
+
+# Special reverse rule for people & body part emoji:
+# don't break between relevant emoji and $EmojiMods
+$EmojiMods $EmojiVar? $EmojiForMods;
## -------------------------------------------------
$SP+ $CM* $QU;
# LB 16
-$SP+ $CM* $CL;
+$SP+ $CM* ($CL | $CP);
# LB 17
$SP+ $CM* $B2;
+# LB 21
+$CM* ($HY | $BA) $CM* $HL;
+
# LB 25
($CM* ($IS | $SY))+ $CM* $NU;
-$CL $CM* ($NU | $IS | $SY);
+($CL | $CP) $CM* ($NU | $IS | $SY);
# For dictionary-based break
$dictionary $dictionary;
# turn off rule chaining. We don't want to move more
# than necessary.
#
-[$CM $OP $QU $CL $B2 $PR $HY $SP $dictionary]+ [^$CM $OP $QU $CL $B2 $PR $HY $dictionary];
+[$CM $OP $QU $CL $CP $B2 $PR $HY $BA $SP $dictionary]+ [^$CM $OP $QU $CL $CP $B2 $PR $HY $BA $dictionary];
$dictionary $dictionary;