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