line_normal_phrase_cj.txt (15069B)
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_normal_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=normal (BCP47 -u-lb-normal) as defined for Chinese & Japanese. 16 # It sets characters of class CJ to behave like ID. 17 # In addition, it allows breaks: 18 # * before 301C, 30A0 (both NS) 19 # It allows breaking before 201C and after 201D, for zh_Hans, zh_Hant, and ja. 20 # 21 # The content is the same as line_normal_cj.txt except the following 22 # 1. Add CJK into dictionary. 23 # 2. Add East Asian Width with class F, W and H into $ALPlus. 24 25 # 26 # Character Classes defined by TR 14. 27 # 28 29 !!chain; 30 !!quoted_literals_only; 31 32 $AI = [:LineBreak = Ambiguous:]; 33 $AK = [:LineBreak = Aksara:]; 34 $AL = [:LineBreak = Alphabetic:]; 35 $AP = [:LineBreak = Aksara_Prebase:]; 36 $AS = [:LineBreak = Aksara_Start:]; 37 $BA = [:LineBreak = Break_After:]; 38 $HH = [:LineBreak = Unambiguous_Hyphen:]; 39 $BB = [:LineBreak = Break_Before:]; 40 $BK = [:LineBreak = Mandatory_Break:]; 41 $B2 = [:LineBreak = Break_Both:]; 42 $CB = [:LineBreak = Contingent_Break:]; 43 $CJ = [:LineBreak = Conditional_Japanese_Starter:]; 44 $CL = [[:LineBreak = Close_Punctuation:] \u201d]; 45 # $CM = [:LineBreak = Combining_Mark:]; 46 $CP = [:LineBreak = Close_Parenthesis:]; 47 $CR = [:LineBreak = Carriage_Return:]; 48 $EB = [:LineBreak = EB:]; 49 $EM = [:LineBreak = EM:]; 50 $EX = [:LineBreak = Exclamation:]; 51 $GL = [:LineBreak = Glue:]; 52 $HL = [:LineBreak = Hebrew_Letter:]; 53 $HY = [:LineBreak = Hyphen:]; 54 $H2 = [:LineBreak = H2:]; 55 $H3 = [:LineBreak = H3:]; 56 # CSS Normal tailoring: CJ resolves to ID 57 $ID = [[:LineBreak = Ideographic:] $CJ]; 58 $IN = [:LineBreak = Inseperable:]; 59 $IS = [:LineBreak = Infix_Numeric:]; 60 $JL = [:LineBreak = JL:]; 61 $JV = [:LineBreak = JV:]; 62 $JT = [:LineBreak = JT:]; 63 $LF = [:LineBreak = Line_Feed:]; 64 $NL = [:LineBreak = Next_Line:]; 65 $NSX = [\u301C \u30A0]; 66 $NS = [[:LineBreak = Nonstarter:] - $NSX]; 67 $NU = [:LineBreak = Numeric:]; 68 $OP = [[:LineBreak = Open_Punctuation:] \u201c]; 69 $PO = [:LineBreak = Postfix_Numeric:]; 70 $PR = [:LineBreak = Prefix_Numeric:]; 71 $QU = [[:LineBreak = Quotation:] - [\u201c\u201d]]; 72 $RI = [:LineBreak = Regional_Indicator:]; 73 $SA = [:LineBreak = Complex_Context:]; 74 $SG = [:LineBreak = Surrogate:]; 75 $SP = [:LineBreak = Space:]; 76 $SY = [:LineBreak = Break_Symbols:]; 77 $VF = [:LineBreak = Virama_Final:]; 78 $VI = [:LineBreak = Virama:]; 79 $WJ = [:LineBreak = Word_Joiner:]; 80 $XX = [:LineBreak = Unknown:]; 81 $ZW = [:LineBreak = ZWSpace:]; 82 $ZWJ = [:LineBreak = ZWJ:]; 83 84 $EastAsian = [\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) and $dictionaryCJK. 97 98 # Add CJK dictionary 99 $Han = [:Han:]; 100 $Katakana = [:Katakana:]; 101 $Hiragana = [:Hiragana:]; 102 $HangulSyllable = [\uac00-\ud7a3]; 103 $ComplexContext = [:LineBreak = Complex_Context:]; 104 $KanaKanji = [$Han $Hiragana $Katakana \u30fc]; 105 $dictionaryCJK = [$KanaKanji $HangulSyllable]; 106 $dictionary = [$ComplexContext $dictionaryCJK]; 107 108 109 # 110 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width), 111 # SA (Dictionary chars, excluding Mn and Mc) 112 # SG (Unpaired Surrogates) 113 # XX (Unknown, unassigned) 114 # as $AL (Alphabetic) 115 # 116 # Let fullwidth-ASCII digits and letters be part of words. 117 $FW_alphanum = [\uff10-\uff19\uff21-\uff3a\uff41-\uff5a]; 118 $ALPlus = [$AL $AI $SG $XX $FW_alphanum [$dictionary-[[: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 $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 205 # LB 13 Don't break before ']' or '!' or '/', even after spaces. 206 # 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 $LB20NonBreaks $CM* ($BA | $HH | $HY | $NS); 338 339 340 ^$CM+ ($BA | $HH | $HY | $NS); 341 342 $BB $CM* [^$CB]; # $BB x 343 $BB $CM* $LB20NonBreaks; 344 345 # LB 21a Do not break after the hyphen in Hebrew + Hyphen + non-Hebrew 346 # HL (HY | HH) x [^HL] 347 # 348 $HL $CM* ($HY | $HH) $CM* [^$CB $HL]?; 349 350 # LB 21b (forward) Don't break between SY and HL 351 # (break between HL and SY already disallowed by LB 13 above) 352 $SY $CM* $HL; 353 354 # LB 22 Do not break before ellipses 355 # 356 $LB20NonBreaks $CM* $IN; 357 ^$CM+ $IN; 358 359 360 # LB 23 361 # 362 ($ALPlus | $HL) $CM* $NU; 363 ^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL 364 $NU $CM* ($ALPlus | $HL); 365 366 # LB 23a 367 # 368 $PR $CM* ($ID | $EB | $EM); 369 ($ID | $EB | $EM) $CM* $PO; 370 371 372 # 373 # LB 24 374 # 375 ($PR | $PO) $CM* ($ALPlus | $HL); 376 ($ALPlus | $HL) $CM* ($PR | $PO); 377 ^$CM+ ($PR | $PO); # Rule 10, any otherwise unattached CM behaves as AL 378 379 # 380 # LB 25 Numbers. 381 # 382 (($PR | $PO) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))* 383 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?; 384 385 # LB 26 Do not break a Korean syllable 386 # 387 $JL $CM* ($JL | $JV | $H2 | $H3); 388 ($JV | $H2) $CM* ($JV | $JT); 389 ($JT | $H3) $CM* $JT; 390 391 # LB 27 Treat korean Syllable Block the same as ID (don't break it) 392 ($JL | $JV | $JT | $H2 | $H3) $CM* $PO; 393 $PR $CM* ($JL | $JV | $JT | $H2 | $H3); 394 395 396 # LB 28 Do not break between alphabetics 397 # 398 ($ALPlus | $HL) $CM* ($ALPlus | $HL); 399 ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL 400 401 #LB 28a Do not break Orthographic syllables 402 ($AP $CM*)? ($AS | $AK | [◌] ) ($CM* $VI $CM* ($AK | [◌] ))* ($CM* $VI | (($CM* ($AS | $AK | [◌] ) )? $CM* $VF))?; 403 404 # LB 29 405 $IS $CM* ($ALPlus | $HL); 406 407 # LB 30 408 ($ALPlus | $HL | $NU) $CM* [$OP - $EastAsian]; 409 ^$CM+ [$OP - $EastAsian]; # The $CM+ is from rule 10, an unattached CM is treated as AL. 410 [$CP - $EastAsian] $CM* ($ALPlus | $HL | $NU); 411 412 # LB 30a Do not break between regional indicators. Break after pairs of them. 413 # Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM. 414 $RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HH $HY $NS $IN $CM]]; 415 $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]]; 416 $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}]; 417 # note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?' 418 # because of the chain-out behavior difference. The rule must chain out only from the [set characters], 419 # not from the preceding $RI or $CM, which it would be able to do if the set were optional. 420 421 # LB30b Do not break between an emoji base (or potential emoji) and an emoji modifier. 422 $EB $CM* $EM; 423 $ExtPictUnassigned $CM* $EM; 424 425 # LB 31 Break everywhere else. 426 # Match a single code point if no other rule applies. 427 .;