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