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