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