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