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