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. 5# 6# file: line_normal.txt 7# 8# Line Breaking Rules 9# Implement default line breaking as defined by 10# Unicode Standard Annex #14 Revision 40 for Unicode 11.0 11# http://www.unicode.org/reports/tr14/, with the following modification: 12# 13# Boundaries between hyphens and following letters are suppressed when 14# there is a boundary preceding the hyphen. See rule 20.9 15# 16# This tailors the line break behavior to correspond to CSS 17# line-break=normal (BCP47 -u-lb-normal) as defined for languages other than 18# Chinese & Japanese. 19# It sets characters of class CJ to behave like ID. 20 21# 22# Character Classes defined by TR 14. 23# 24 25!!chain; 26!!quoted_literals_only; 27 28$AI = [:LineBreak = Ambiguous:]; 29$AL = [:LineBreak = Alphabetic:]; 30$BA = [:LineBreak = Break_After:]; 31$HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA. 32$BB = [:LineBreak = Break_Before:]; 33$BK = [:LineBreak = Mandatory_Break:]; 34$B2 = [:LineBreak = Break_Both:]; 35$CB = [:LineBreak = Contingent_Break:]; 36$CJ = [:LineBreak = Conditional_Japanese_Starter:]; 37$CL = [:LineBreak = Close_Punctuation:]; 38# $CM = [:LineBreak = Combining_Mark:]; 39$CP = [:LineBreak = Close_Parenthesis:]; 40$CR = [:LineBreak = Carriage_Return:]; 41$EB = [:LineBreak = EB:]; 42$EM = [:LineBreak = EM:]; 43$EX = [:LineBreak = Exclamation:]; 44$GL = [:LineBreak = Glue:]; 45$HL = [:LineBreak = Hebrew_Letter:]; 46$HY = [:LineBreak = Hyphen:]; 47$H2 = [:LineBreak = H2:]; 48$H3 = [:LineBreak = H3:]; 49# CSS Normal tailoring: CJ resolves to ID 50$ID = [[:LineBreak = Ideographic:] $CJ]; 51$IN = [:LineBreak = Inseperable:]; 52$IS = [:LineBreak = Infix_Numeric:]; 53$JL = [:LineBreak = JL:]; 54$JV = [:LineBreak = JV:]; 55$JT = [:LineBreak = JT:]; 56$LF = [:LineBreak = Line_Feed:]; 57$NL = [:LineBreak = Next_Line:]; 58$NS = [:LineBreak = Nonstarter:]; 59$NU = [:LineBreak = Numeric:]; 60$OP = [:LineBreak = Open_Punctuation:]; 61$PO = [:LineBreak = Postfix_Numeric:]; 62$PR = [:LineBreak = Prefix_Numeric:]; 63$QU = [:LineBreak = Quotation:]; 64$RI = [:LineBreak = Regional_Indicator:]; 65$SA = [:LineBreak = Complex_Context:]; 66$SG = [:LineBreak = Surrogate:]; 67$SP = [:LineBreak = Space:]; 68$SY = [:LineBreak = Break_Symbols:]; 69$WJ = [:LineBreak = Word_Joiner:]; 70$XX = [:LineBreak = Unknown:]; 71$ZW = [:LineBreak = ZWSpace:]; 72$ZWJ = [:LineBreak = ZWJ:]; 73 74# By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly 75# list it in the numerous rules that use CM. 76# By LB1, SA characters with general categor of Mn or Mc also resolve to CM. 77 78$CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]]; 79 80# Dictionary character set, for triggering language-based break engines. Currently 81# limited to LineBreak=Complex_Context (SA). 82 83$dictionary = [$SA]; 84 85# 86# Rule LB1. By default, treat AI (characters with ambiguous east Asian width), 87# SA (Dictionary chars, excluding Mn and Mc) 88# SG (Unpaired Surrogates) 89# XX (Unknown, unassigned) 90# as $AL (Alphabetic) 91# 92$ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]]; 93 94 95## ------------------------------------------------- 96 97# 98# CAN_CM is the set of characters that may combine with CM combining chars. 99# Note that Linebreak UAX 14's concept of a combining char and the rules 100# for what they can combine with are _very_ different from the rest of Unicode. 101# 102# Note that $CM itself is left out of this set. If CM is needed as a base 103# it must be listed separately in the rule. 104# 105$CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs 106$CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs 107 108# 109# AL_FOLLOW set of chars that can unconditionally follow an AL 110# Needed in rules where stand-alone $CM s are treated as AL. 111# 112$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]; 113 114 115# 116# Rule LB 4, 5 Mandatory (Hard) breaks. 117# 118$LB4Breaks = [$BK $CR $LF $NL]; 119$LB4NonBreaks = [^$BK $CR $LF $NL $CM]; 120$CR $LF {100}; 121 122# 123# LB 6 Do not break before hard line breaks. 124# 125$LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks. 126$CAN_CM $CM* $LB4Breaks {100}; 127^$CM+ $LB4Breaks {100}; 128 129# LB 7 x SP 130# x ZW 131$LB4NonBreaks [$SP $ZW]; 132$CAN_CM $CM* [$SP $ZW]; 133^$CM+ [$SP $ZW]; 134 135# 136# LB 8 Break after zero width space 137# ZW SP* ÷ 138# 139$LB8Breaks = [$LB4Breaks $ZW]; 140$LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]]; 141$ZW $SP* / [^$SP $ZW $LB4Breaks]; 142 143# LB 8a ZWJ x Do not break Emoji ZWJ sequences. 144# 145$ZWJ [^$CM]; 146 147# LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL 148# $CM not covered by the above needs to behave like $AL 149# See definition of $CAN_CM. 150 151$CAN_CM $CM+; # Stick together any combining sequences that don't match other rules. 152^$CM+; 153 154# 155# LB 11 Do not break before or after WORD JOINER & related characters. 156# 157$CAN_CM $CM* $WJ; 158$LB8NonBreaks $WJ; 159^$CM+ $WJ; 160 161$WJ $CM* .; 162 163# 164# LB 12 Do not break after NBSP and related characters. 165# GL x 166# 167$GL $CM* .; 168 169# 170# LB 12a Do not break before NBSP and related characters ... 171# [^SP BA HY] x GL 172# 173[[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GL; 174^$CM+ $GL; 175 176 177 178# 179# LB 13 Don't break before ']' or '!' or ';' or '/', even after spaces. 180# 181$LB8NonBreaks $CL; 182$CAN_CM $CM* $CL; 183^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL 184 185$LB8NonBreaks $CP; 186$CAN_CM $CM* $CP; 187^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL 188 189$LB8NonBreaks $EX; 190$CAN_CM $CM* $EX; 191^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL 192 193$LB8NonBreaks $IS; 194$CAN_CM $CM* $IS; 195^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL 196 197$LB8NonBreaks $SY; 198$CAN_CM $CM* $SY; 199^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL 200 201 202# 203# LB 14 Do not break after OP, even after spaces 204# 205$OP $CM* $SP* .; 206 207$OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL 208 # by rule 8, CM following a SP is stand-alone. 209 210# LB 15 211$QU $CM* $SP* $OP; 212 213# LB 16 214($CL | $CP) $CM* $SP* $NS; 215 216# LB 17 217$B2 $CM* $SP* $B2; 218 219# 220# LB 18 Break after spaces. 221# 222$LB18NonBreaks = [$LB8NonBreaks - [$SP]]; 223$LB18Breaks = [$LB8Breaks $SP]; 224 225 226# LB 19 227# x QU 228$LB18NonBreaks $CM* $QU; 229^$CM+ $QU; 230 231# QU x 232$QU $CM* .; 233 234# LB 20 235# <break> $CB 236# $CB <break> 237# 238$LB20NonBreaks = [$LB18NonBreaks - $CB]; 239 240# LB 20.09 Don't break between Hyphens and Letters when there is a break preceding the hyphen. 241# Originally added as a Finnish tailoring, now promoted to default ICU behavior. 242# Note: this is not default UAX-14 behaviour. See issue ICU-8151. 243# 244^($HY | $HH) $CM* $ALPlus; 245 246# LB 21 x (BA | HY | NS) 247# BB x 248# 249$LB20NonBreaks $CM* ($BA | $HY | $NS); 250 251 252^$CM+ ($BA | $HY | $NS); 253 254$BB $CM* [^$CB]; # $BB x 255$BB $CM* $LB20NonBreaks; 256 257# LB 21a Don't break after Hebrew + Hyphen 258# HL (HY | BA) x 259# 260$HL $CM* ($HY | $BA) $CM* [^$CB]?; 261 262# LB 21b (forward) Don't break between SY and HL 263# (break between HL and SY already disallowed by LB 13 above) 264$SY $CM* $HL; 265 266# LB 22 267($ALPlus | $HL) $CM* $IN; 268^$CM+ $IN; # by rule 10, any otherwise unattached CM behaves as AL 269$EX $CM* $IN; 270($ID | $EB | $EM) $CM* $IN; 271$IN $CM* $IN; 272$NU $CM* $IN; 273 274 275# $LB 23 276# 277($ALPlus | $HL) $CM* $NU; 278^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL 279$NU $CM* ($ALPlus | $HL); 280 281# LB 23a 282# 283$PR $CM* ($ID | $EB | $EM); 284($ID | $EB | $EM) $CM* $PO; 285 286 287# 288# LB 24 289# 290($PR | $PO) $CM* ($ALPlus | $HL); 291($ALPlus | $HL) $CM* ($PR | $PO); 292^$CM+ ($PR | $PO); # Rule 10, any otherwise unattached CM behaves as AL 293 294# 295# LB 25 Numbers. 296# 297(($PR | $PO) $CM*)? (($OP | $HY) $CM*)? $NU ($CM* ($NU | $SY | $IS))* 298 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?; 299 300# LB 26 Do not break a Korean syllable 301# 302$JL $CM* ($JL | $JV | $H2 | $H3); 303($JV | $H2) $CM* ($JV | $JT); 304($JT | $H3) $CM* $JT; 305 306# LB 27 Treat korean Syllable Block the same as ID (don't break it) 307($JL | $JV | $JT | $H2 | $H3) $CM* $IN; 308($JL | $JV | $JT | $H2 | $H3) $CM* $PO; 309$PR $CM* ($JL | $JV | $JT | $H2 | $H3); 310 311 312# LB 28 Do not break between alphabetics 313# 314($ALPlus | $HL) $CM* ($ALPlus | $HL); 315^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL 316 317# LB 29 318$IS $CM* ($ALPlus | $HL); 319 320# LB 30 321($ALPlus | $HL | $NU) $CM* $OP; 322^$CM+ $OP; # The $CM+ is from rule 10, an unattached CM is treated as AL. 323$CP $CM* ($ALPlus | $HL | $NU); 324 325# LB 30a Do not break between regional indicators. Break after pairs of them. 326# Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM. 327$RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]]; 328$RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]]; 329$RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $ZWJ {eof}]; 330# note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?' 331# because of the chain-out behavior difference. The rule must chain out only from the [set characters], 332# not from the preceding $RI or $CM, which it would be able to do if the set were optional. 333 334# LB 30b Do not break between an Emoji Base and an Emoji Modifier 335$EB $CM* $EM; 336 337# LB 31 Break everywhere else. 338# Match a single code point if no other rule applies. 339.; 340