line_loose_phrase_cj.txt (16495B)
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 (as well as the rest of the HH class) 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 $AK = [:LineBreak = Aksara:]; 44 $AL = [:LineBreak = Alphabetic:]; 45 $AP = [:LineBreak = Aksara_Prebase:]; 46 $AS = [:LineBreak = Aksara_Start:]; 47 $BA = [:LineBreak = Break_After:]; 48 $HH = [:LineBreak = Unambiguous_Hyphen:]; 49 $BB = [:LineBreak = Break_Before:]; 50 $BK = [:LineBreak = Mandatory_Break:]; 51 $B2 = [:LineBreak = Break_Both:]; 52 $CB = [:LineBreak = Contingent_Break:]; 53 $CJ = [:LineBreak = Conditional_Japanese_Starter:]; 54 $CL = [[:LineBreak = Close_Punctuation:] \u201d]; 55 # $CM = [:LineBreak = Combining_Mark:]; 56 $CP = [:LineBreak = Close_Parenthesis:]; 57 $CR = [:LineBreak = Carriage_Return:]; 58 $EB = [:LineBreak = EB:]; 59 $EM = [:LineBreak = EM:]; 60 $EXX = [\uFF01 \uFF1F]; 61 $EX = [[:LineBreak = Exclamation:] - $EXX]; 62 $GL = [:LineBreak = Glue:]; 63 $HL = [:LineBreak = Hebrew_Letter:]; 64 $HY = [:LineBreak = Hyphen:]; 65 $H2 = [:LineBreak = H2:]; 66 $H3 = [:LineBreak = H3:]; 67 # CSS Loose tailoring: CJ resolves to ID 68 $ID = [[:LineBreak = Ideographic:] $CJ]; 69 $IN = [:LineBreak = Inseperable:]; 70 $IS = [:LineBreak = Infix_Numeric:]; 71 $JL = [:LineBreak = JL:]; 72 $JV = [:LineBreak = JV:]; 73 $JT = [:LineBreak = JT:]; 74 $LF = [:LineBreak = Line_Feed:]; 75 $NL = [:LineBreak = Next_Line:]; 76 $NSX = [\u301C \u30A0 \u3005 \u303B \u309D \u309E \u30FD \u30FE \u203C \u2047 \u2048 \u2049 \u30FB \uFF1A \uFF1B \uFF65]; 77 $NS = [[:LineBreak = Nonstarter:] - $NSX]; 78 $NU = [:LineBreak = Numeric:]; 79 $OP = [[:LineBreak = Open_Punctuation:] \u201c]; 80 $POX = [\u00B0 \u2030 \u2032 \u2033 \u2035 \u2103 \u2109 \uFE6A \uFF05 \uFFE0]; 81 $PO = [[:LineBreak = Postfix_Numeric:] - $POX]; 82 $PRX = [\u00A4 \u00B1 \u20AC \u2116 \uFE69 \uFF04 \uFFE1 \uFFE5 \uFFE6]; 83 $PR = [[:LineBreak = Prefix_Numeric:] - $PRX]; 84 $QU = [[:LineBreak = Quotation:] - [\u201c\u201d]]; 85 $RI = [:LineBreak = Regional_Indicator:]; 86 $SA = [:LineBreak = Complex_Context:]; 87 $SG = [:LineBreak = Surrogate:]; 88 $SP = [:LineBreak = Space:]; 89 $SY = [:LineBreak = Break_Symbols:]; 90 $VF = [:LineBreak = Virama_Final:]; 91 $VI = [:LineBreak = Virama:]; 92 $WJ = [:LineBreak = Word_Joiner:]; 93 $XX = [:LineBreak = Unknown:]; 94 $ZW = [:LineBreak = ZWSpace:]; 95 $ZWJ = [:LineBreak = ZWJ:]; 96 97 $EastAsian = [\p{ea=F}\p{ea=W}\p{ea=H}]; 98 99 $ExtPictUnassigned = [\p{Extended_Pictographic} & \p{Cn}]; 100 101 # By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly 102 # list it in the numerous rules that use CM. 103 # By LB1, SA characters with general categor of Mn or Mc also resolve to CM. 104 105 $CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]]; 106 $CMX = [[$CM] - [$ZWJ]]; 107 108 # Dictionary character set, for triggering language-based break engines. Currently 109 # limited to LineBreak=Complex_Context (SA) and $dictionaryCJK. 110 111 # Add CJK dictionary 112 $Han = [:Han:]; 113 $Katakana = [:Katakana:]; 114 $Hiragana = [:Hiragana:]; 115 $HangulSyllable = [\uac00-\ud7a3]; 116 $ComplexContext = [:LineBreak = Complex_Context:]; 117 $KanaKanji = [$Han $Hiragana $Katakana \u30fc]; 118 $dictionaryCJK = [$KanaKanji $HangulSyllable]; 119 $dictionary = [$ComplexContext $dictionaryCJK]; 120 121 122 # 123 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width), 124 # SA (Dictionary chars, excluding Mn and Mc) 125 # SG (Unpaired Surrogates) 126 # XX (Unknown, unassigned) 127 # as $AL (Alphabetic) 128 # 129 # Let fullwidth-ASCII digits and letters be part of words. 130 $FW_alphanum = [\uff10-\uff19\uff21-\uff3a\uff41-\uff5a]; 131 $ALPlus = [$AL $AI $SG $XX $FW_alphanum [$dictionary-[[:Mn:][:Mc:]]]]; 132 133 134 ## ------------------------------------------------- 135 136 # 137 # CAN_CM is the set of characters that may combine with CM combining chars. 138 # Note that Linebreak UAX 14's concept of a combining char and the rules 139 # for what they can combine with are _very_ different from the rest of Unicode. 140 # 141 # Note that $CM itself is left out of this set. If CM is needed as a base 142 # it must be listed separately in the rule. 143 # 144 $CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs 145 $CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs 146 147 # 148 # AL_FOLLOW set of chars that can unconditionally follow an AL 149 # Needed in rules where stand-alone $CM s are treated as AL. 150 # 151 $AL_FOLLOW = [$BK $CR $LF $NL $ZW $SP $CL $CP $EX $HL $IS $SY $WJ $GL [$OP - $EastAsian] $QU $BA $HH $HY $NS $IN $NU $PR $PO $POX $ALPlus]; 152 153 154 # 155 # Rule LB 4, 5 Mandatory (Hard) breaks. 156 # 157 $LB4Breaks = [$BK $CR $LF $NL]; 158 $LB4NonBreaks = [^$BK $CR $LF $NL $CM]; 159 $CR $LF {100}; 160 161 # 162 # LB 6 Do not break before hard line breaks. 163 # 164 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks. 165 $CAN_CM $CM* $LB4Breaks {100}; 166 ^$CM+ $LB4Breaks {100}; 167 168 # LB 7 x SP 169 # x ZW 170 $LB4NonBreaks [$SP $ZW]; 171 $CAN_CM $CM* [$SP $ZW]; 172 ^$CM+ [$SP $ZW]; 173 174 # 175 # LB 8 Break after zero width space 176 # ZW SP* ÷ 177 # 178 $LB8Breaks = [$LB4Breaks $ZW]; 179 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]]; 180 $ZW $SP* / [^$SP $ZW $LB4Breaks]; 181 182 # LB 8a ZWJ x Do not break Emoji ZWJ sequences. 183 # 184 $ZWJ [^$CM]; 185 186 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL 187 # $CM not covered by the above needs to behave like $AL 188 # See definition of $CAN_CM. 189 190 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules. 191 ^$CM+; 192 193 # 194 # LB 11 Do not break before or after WORD JOINER & related characters. 195 # 196 $CAN_CM $CM* $WJ; 197 $LB8NonBreaks $WJ; 198 ^$CM+ $WJ; 199 200 $WJ $CM* .; 201 202 # 203 # LB 12 Do not break after NBSP and related characters. 204 # GL x 205 # 206 $GL $CM* .; 207 208 # 209 # LB 12a Do not break before NBSP and related characters ... 210 # [^SP BA HY HH] x GL 211 # 212 [[$LB8NonBreaks] - [$SP $BA $HY $HH]] $CM* $GL; 213 ^$CM+ $GL; 214 215 216 217 # LB 13 Don't break before ']' or '!' or '/', even after spaces. 218 # 219 # Do not include $EXX here 220 $LB8NonBreaks $CL; 221 $CAN_CM $CM* $CL; 222 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL 223 224 $LB8NonBreaks $CP; 225 $CAN_CM $CM* $CP; 226 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL 227 228 $LB8NonBreaks $EX; 229 $CAN_CM $CM* $EX; 230 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL 231 232 $LB8NonBreaks $SY; 233 $CAN_CM $CM* $SY; 234 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL 235 236 237 # 238 # LB 14 Do not break after OP, even after spaces 239 # Note subtle interaction with "SP IS /" rules in LB14a. 240 # This rule consumes the SP, chaining happens on the IS, effectivley overriding the SP IS rules, 241 # which is the desired behavior. 242 # 243 $OP $CM* $SP* .; 244 245 $OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL 246 # by rule 8, CM following a SP is stand-alone. 247 248 249 # LB 15a 250 ($OP $CM* $SP+ | [$OP $QU $GL] $CM*) ([\p{Pi} & $QU] $CM* $SP*)+ .; 251 ($OP $CM* $SP+ | [$OP $QU $GL] $CM*) ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?; 252 ^([\p{Pi} & $QU] $CM* $SP*)+ .; 253 ^([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?; 254 255 # LB 15b 256 $LB8NonBreaks [\p{Pf} & $QU] $CM* [$SP $GL $WJ $CL $QU $CP $EX $IS $SY $BK $CR $LF $NL $ZW {eof}]; 257 $CAN_CM $CM* [\p{Pf} & $QU] $CM* [$SP $GL $WJ $CL $QU $CP $EX $IS $SY $BK $CR $LF $NL $ZW {eof}]; 258 ^$CM+ [\p{Pf} & $QU] $CM* [$SP $GL $WJ $CL $QU $CP $EX $IS $SY $BK $CR $LF $NL $ZW {eof}]; 259 260 # Messy interaction: manually chain between LB 15b and LB 15a on Pf Pi. 261 $LB8NonBreaks [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ .; 262 $LB8NonBreaks [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?; 263 $CAN_CM $CM* [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ .; 264 $CAN_CM $CM* [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?; 265 ^$CM+ [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ .; 266 ^$CM+ [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?; 267 268 269 # LB 15c Force a break before start of a number with a leading decimal pt, e.g. " .23" 270 # Note: would be simpler to express as "$SP / $IS $CM* $NU;", but ICU rules have limitations. 271 # See issue ICU-20303 272 273 274 $CanFollowIS = [$BK $CR $LF $NL $SP $ZW $WJ $GL $CL $CP $EX $IS $SY $QU $BA $HH $HY $NS $ALPlus $HL $IN]; 275 $SP $IS / [^ $CanFollowIS $NU $CM]; 276 $SP $IS $CM* $CMX / [^ $CanFollowIS $NU $CM]; 277 278 # 279 # LB 15d Do not break before numeric separators (IS), even after spaces. 280 # SP IS QU is handled below as part of LB 19. 281 282 [$LB8NonBreaks - $SP] $IS; 283 $SP $IS $CM* [$CanFollowIS {eof}]; 284 $SP $IS $CM* $ZWJ [^$CM $NU]; 285 286 $CAN_CM $CM* $IS; 287 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL 288 289 290 # LB 16 291 # Do not break between closing punctuation and $NS, even with intervening spaces 292 # But DO allow a break between closing punctuation and $NSX, don't include it here 293 ($CL | $CP) $CM* $SP* $NS; 294 295 # LB 17 296 $B2 $CM* $SP* $B2; 297 298 # 299 # LB 18 Break after spaces. 300 # 301 $LB18NonBreaks = [$LB8NonBreaks - [$SP]]; 302 $LB18Breaks = [$LB8Breaks $SP]; 303 304 305 # LB 19 and LB 19a. 306 # Instead of implementing both as keep-together rules as in UAX #14, we have an 307 # East_Asian_Width and General_Category-insensitive keep-together rule 308 # equivalent to the old LB19 × QU and QU ×, and then we poke holes into it based 309 # on context. This avoids having to do manual chaining over multiple characters 310 # with many other rules over multiple characters, as a keep-together LB19a would 311 # overlap in context with at least LB14, LB15a, LB15a, LB15d, LB30a, and itself. 312 $LB18NonBreaks $CM* $QU; 313 ^$CM+ $QU; 314 315 [$LB18NonBreaks & $EastAsian - [$OP $GL]] / [\p{Pi} & $QU] $CM* [ $EastAsian - $CM]; 316 [$LB18NonBreaks & $EastAsian - [$OP $GL]] $CM* $CMX / [\p{Pi} & $QU] $CM* [ $EastAsian - $CM]; 317 318 $QU $CM* .; 319 [$LB18NonBreaks & $EastAsian] $CM* [\p{Pf} & $QU] / [ $EastAsian - [$NS $BA $EX $CL $IN $IS $GL $CM]]; 320 [$LB18NonBreaks & $EastAsian] $CM* [\p{Pf} & $QU] $CM* $CMX / [ $EastAsian - [$NS $BA $EX $CL $IN $IS $GL $CM]]; 321 322 # LB 20 323 # <break> $CB 324 # $CB <break> 325 # 326 $LB20NonBreaks = [$LB18NonBreaks - $CB]; 327 328 # LB 20a Don't break between Hyphens and Letters when there is a break preceding the hyphen. 329 # Originally added as a Finnish tailoring, promoted to default ICU behavior (ICU-8151), 330 # and then to default UAX #14 behaviour (UTC-179-C32). 331 # 332 ^($HY | $HH) $CM* ($ALPlus | $HL); 333 $GL $CM* ($HY | $HH) $CM* ($ALPlus | $HL ); 334 # Non-breaking CB from LB8a: 335 $CB $CM* $ZWJ ($HY | $HH) $CM* ($ALPlus | $HL ); 336 # Non-breaking SP from LB14: 337 $OP $CM* $SP+ ($HY | $HH) $CM* ($ALPlus | $HL ); 338 # Non-breaking SP from LB15a: 339 ($OP $CM* $SP+ | [$OP $QU $GL] $CM*) ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* ($ALPlus | $HL ); 340 ^([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* ($ALPlus | $HL ); 341 # Non-breaking SP from LB15a following LB15b: 342 $LB8NonBreaks [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* ($ALPlus | $HL ); 343 $CAN_CM $CM* [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* ($ALPlus | $HL ); 344 ^$CM+ [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* ($ALPlus | $HL ); 345 346 # LB 21 x (BA | HH | HY | NS) 347 # BB x 348 # 349 # DO allow breaks here before $NSX, so don't include it. 350 # And DO allow breaks between ID and $HH, so split out the handling of ID and do not include $HH for them. 351 [$LB20NonBreaks - $ID] $CM* ($BA | $HH | $HY | $NS); 352 $ID $CM* ($BA | $HY | $NS); 353 354 355 ^$CM+ ($BA | $HH | $HY | $NS); 356 357 $BB $CM* [^$CB]; # $BB x 358 $BB $CM* $LB20NonBreaks; 359 360 # LB 21a Do not break after the hyphen in Hebrew + Hyphen + non-Hebrew 361 # HL (HY | HH) x [^HL] 362 # 363 $HL $CM* ($HY | $HH) $CM* [^$CB $HL]?; 364 365 # LB 21b (forward) Don't break between SY and HL 366 # (break between HL and SY already disallowed by LB 13 above) 367 $SY $CM* $HL; 368 369 370 # LB 22 Do not break before ellipses 371 # 372 [$LB20NonBreaks - $IN] $CM* $IN; # line_loose tailoring 373 ^$CM+ $IN; 374 375 376 # LB 23 377 # 378 ($ALPlus | $HL) $CM* $NU; 379 ^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL 380 $NU $CM* ($ALPlus | $HL); 381 382 # LB 23a 383 # Do not include $POX here 384 # 385 $PR $CM* ($ID | $EB | $EM); 386 ($ID | $EB | $EM) $CM* $PO; 387 388 389 # 390 # LB 24 391 # 392 # Do not include $PRX here 393 ($PR | $PO | $POX) $CM* ($ALPlus | $HL); 394 ($ALPlus | $HL) $CM* ($PR | $PO | $POX); # TODO: should this be ($PR | $PRX | $PO) 395 ^$CM+ ($PR | $PO | $POX); # Rule 10, any otherwise unattached CM behaves as AL 396 397 # 398 # LB 25 Numbers. 399 # 400 # Here do not include $PRX at the beginning or $POX at the end 401 (($PR | $PO | $POX) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))* 402 ($CM* ($CL | $CP))? ($CM* ($PR | $PRX | $PO))?; 403 404 # LB 26 Do not break a Korean syllable 405 # 406 $JL $CM* ($JL | $JV | $H2 | $H3); 407 ($JV | $H2) $CM* ($JV | $JT); 408 ($JT | $H3) $CM* $JT; 409 410 # LB 27 Treat korean Syllable Block the same as ID (don't break it) 411 # Do not include $POX or $PRX here 412 ($JL | $JV | $JT | $H2 | $H3) $CM* $PO; 413 $PR $CM* ($JL | $JV | $JT | $H2 | $H3); 414 415 416 # LB 28 Do not break between alphabetics 417 # 418 ($ALPlus | $HL) $CM* ($ALPlus | $HL); 419 ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL 420 421 #LB 28a Do not break Orthographic syllables 422 ($AP $CM*)? ($AS | $AK | [◌] ) ($CM* $VI $CM* ($AK | [◌] ))* ($CM* $VI | (($CM* ($AS | $AK | [◌] ) )? $CM* $VF))?; 423 424 # LB 29 425 $IS $CM* ($ALPlus | $HL); 426 427 # LB 30 428 ($ALPlus | $HL | $NU) $CM* [$OP - $EastAsian]; 429 ^$CM+ [$OP - $EastAsian]; # The $CM+ is from rule 10, an unattached CM is treated as AL. 430 [$CP - $EastAsian] $CM* ($ALPlus | $HL | $NU); 431 432 # LB 30a Do not break between regional indicators. Break after pairs of them. 433 # Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM. 434 $RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HH $HY $NS $IN $CM]]; 435 $RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HH $HY $NS $IN $CM]]; 436 $RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HH $HY $NS $IN $ZWJ {eof}]; 437 # note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?' 438 # because of the chain-out behavior difference. The rule must chain out only from the [set characters], 439 # not from the preceding $RI or $CM, which it would be able to do if the set were optional. 440 441 # LB30b Do not break between an emoji base (or potential emoji) and an emoji modifier. 442 $EB $CM* $EM; 443 $ExtPictUnassigned $CM* $EM; 444 445 # LB 31 Break everywhere else. 446 # Match a single code point if no other rule applies. 447 .;