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_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 corresponds to CSS line-break-word-handling=phrase (BCP47 -u-lw-phrase). 15# It sets characters of class CJ to behave like NS. 16# It allows breaking before 201C and after 201D, for zh_Hans, zh_Hant, and ja. 17# 18# The content is the same as line_cj.txt except the following 19# 1. Add CJK into dictionary. 20# 2. Add East Asian Width with class F, W and H into $ALPlus. 21# 22# Character Classes defined by TR 14. 23# 24 25!!chain; 26!!quoted_literals_only; 27 28$AI = [:LineBreak = Ambiguous:]; 29$AL = [:LineBreak = Alphabetic:]; 30$BA = [:LineBreak = Break_After:]; 31$HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA. 32$BB = [:LineBreak = Break_Before:]; 33$BK = [:LineBreak = Mandatory_Break:]; 34$B2 = [:LineBreak = Break_Both:]; 35$CB = [:LineBreak = Contingent_Break:]; 36$CJ = [:LineBreak = Conditional_Japanese_Starter:]; 37$CL = [[:LineBreak = Close_Punctuation:] \u201d]; 38# $CM = [:LineBreak = Combining_Mark:]; 39$CP = [:LineBreak = Close_Parenthesis:]; 40$CR = [:LineBreak = Carriage_Return:]; 41$EB = [:LineBreak = EB:]; 42$EM = [:LineBreak = EM:]; 43$EX = [:LineBreak = Exclamation:]; 44$GL = [:LineBreak = Glue:]; 45$HL = [:LineBreak = Hebrew_Letter:]; 46$HY = [:LineBreak = Hyphen:]; 47$H2 = [:LineBreak = H2:]; 48$H3 = [:LineBreak = H3:]; 49$ID = [:LineBreak = Ideographic:]; 50$IN = [:LineBreak = Inseperable:]; 51$IS = [:LineBreak = Infix_Numeric:]; 52$JL = [:LineBreak = JL:]; 53$JV = [:LineBreak = JV:]; 54$JT = [:LineBreak = JT:]; 55$LF = [:LineBreak = Line_Feed:]; 56$NL = [:LineBreak = Next_Line:]; 57# NS includes CJ for CSS strict line breaking. 58$NS = [[:LineBreak = Nonstarter:] $CJ]; 59$NU = [:LineBreak = Numeric:]; 60$OP = [[:LineBreak = Open_Punctuation:] \u201c]; 61$PO = [:LineBreak = Postfix_Numeric:]; 62$PR = [:LineBreak = Prefix_Numeric:]; 63$QU = [[:LineBreak = Quotation:] - [\u201c\u201d]]; 64$RI = [:LineBreak = Regional_Indicator:]; 65$SA = [:LineBreak = Complex_Context:]; 66$SG = [:LineBreak = Surrogate:]; 67$SP = [:LineBreak = Space:]; 68$SY = [:LineBreak = Break_Symbols:]; 69$WJ = [:LineBreak = Word_Joiner:]; 70$XX = [:LineBreak = Unknown:]; 71$ZW = [:LineBreak = ZWSpace:]; 72$ZWJ = [:LineBreak = ZWJ:]; 73 74# OP30 and CP30 are variants of OP and CP that appear in-line in rule LB30 from UAX 14, 75# without a formal name. Because ICU rules require multiple uses of the expressions, 76# give them a single definition with a name 77 78$OP30 = [$OP - [\p{ea=F}\p{ea=W}\p{ea=H}]]; 79$CP30 = [$CP - [\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) and $dictionaryCJK. 92 93# Add CJK dictionary 94$Han = [:Han:]; 95$Katakana = [:Katakana:]; 96$Hiragana = [:Hiragana:]; 97$HangulSyllable = [\uac00-\ud7a3]; 98$ComplexContext = [:LineBreak = Complex_Context:]; 99$KanaKanji = [$Han $Hiragana $Katakana \u30fc]; 100$dictionaryCJK = [$KanaKanji $HangulSyllable]; 101$dictionary = [$ComplexContext $dictionaryCJK]; 102 103 104# 105# Rule LB1. By default, treat AI (characters with ambiguous east Asian width), 106# SA (Dictionary chars, excluding Mn and Mc) 107# SG (Unpaired Surrogates) 108# XX (Unknown, unassigned) 109# as $AL (Alphabetic) 110# 111# Let fullwidth-ASCII digits and letters be part of words. 112$FW_alphanum = [\uff10-\uff19\uff21-\uff3a\uff41-\uff5a]; 113$ALPlus = [$AL $AI $SG $XX $FW_alphanum [$dictionary-[[:Mn:][:Mc:]]]]; 114 115 116## ------------------------------------------------- 117 118# 119# CAN_CM is the set of characters that may combine with CM combining chars. 120# Note that Linebreak UAX 14's concept of a combining char and the rules 121# for what they can combine with are _very_ different from the rest of Unicode. 122# 123# Note that $CM itself is left out of this set. If CM is needed as a base 124# it must be listed separately in the rule. 125# 126$CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs 127$CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs 128 129# 130# AL_FOLLOW set of chars that can unconditionally follow an AL 131# Needed in rules where stand-alone $CM s are treated as AL. 132# 133$AL_FOLLOW = [$BK $CR $LF $NL $ZW $SP $CL $CP $EX $HL $IS $SY $WJ $GL $OP30 $QU $BA $HY $NS $IN $NU $PR $PO $ALPlus]; 134 135 136# 137# Rule LB 4, 5 Mandatory (Hard) breaks. 138# 139$LB4Breaks = [$BK $CR $LF $NL]; 140$LB4NonBreaks = [^$BK $CR $LF $NL $CM]; 141$CR $LF {100}; 142 143# 144# LB 6 Do not break before hard line breaks. 145# 146$LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks. 147$CAN_CM $CM* $LB4Breaks {100}; 148^$CM+ $LB4Breaks {100}; 149 150# LB 7 x SP 151# x ZW 152$LB4NonBreaks [$SP $ZW]; 153$CAN_CM $CM* [$SP $ZW]; 154^$CM+ [$SP $ZW]; 155 156# 157# LB 8 Break after zero width space 158# ZW SP* ÷ 159# 160$LB8Breaks = [$LB4Breaks $ZW]; 161$LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]]; 162$ZW $SP* / [^$SP $ZW $LB4Breaks]; 163 164# LB 8a ZWJ x Do not break Emoji ZWJ sequences. 165# 166$ZWJ [^$CM]; 167 168# LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL 169# $CM not covered by the above needs to behave like $AL 170# See definition of $CAN_CM. 171 172$CAN_CM $CM+; # Stick together any combining sequences that don't match other rules. 173^$CM+; 174 175# 176# LB 11 Do not break before or after WORD JOINER & related characters. 177# 178$CAN_CM $CM* $WJ; 179$LB8NonBreaks $WJ; 180^$CM+ $WJ; 181 182$WJ $CM* .; 183 184# 185# LB 12 Do not break after NBSP and related characters. 186# GL x 187# 188$GL $CM* .; 189 190# 191# LB 12a Do not break before NBSP and related characters ... 192# [^SP BA HY] x GL 193# 194[[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GL; 195^$CM+ $GL; 196 197 198 199 200# LB 13 Don't break before ']' or '!' or '/', even after spaces. 201# 202$LB8NonBreaks $CL; 203$CAN_CM $CM* $CL; 204^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL 205 206$LB8NonBreaks $CP; 207$CAN_CM $CM* $CP; 208^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL 209 210$LB8NonBreaks $EX; 211$CAN_CM $CM* $EX; 212^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL 213 214$LB8NonBreaks $SY; 215$CAN_CM $CM* $SY; 216^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL 217 218 219# 220# LB 14 Do not break after OP, even after spaces 221# Note subtle interaction with "SP IS /" rules in LB14a. 222# This rule consumes the SP, chaining happens on the IS, effectivley overriding the SP IS rules, 223# which is the desired behavior. 224# 225$OP $CM* $SP* .; 226 227$OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL 228 # by rule 8, CM following a SP is stand-alone. 229 230 231# LB 14a Force a break before start of a number with a leading decimal pt, e.g. " .23" 232# Note: would be simpler to express as "$SP / $IS $CM* $NU;", but ICU rules have limitations. 233# See issue ICU-20303 234 235 236$CanFollowIS = [$BK $CR $LF $NL $SP $ZW $WJ $GL $CL $CP $EX $IS $SY $QU $BA $HY $NS $ALPlus $HL $IN]; 237$SP $IS / [^ $CanFollowIS $NU $CM]; 238$SP $IS $CM* $CMX / [^ $CanFollowIS $NU $CM]; 239 240# 241# LB 14b Do not break before numeric separators (IS), even after spaces. 242 243[$LB8NonBreaks - $SP] $IS; 244$SP $IS $CM* [$CanFollowIS {eof}]; 245$SP $IS $CM* $ZWJ [^$CM $NU]; 246 247$CAN_CM $CM* $IS; 248^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL 249 250 251# LB 15 252$QU $CM* $SP* $OP; 253 254# LB 16 255($CL | $CP) $CM* $SP* $NS; 256 257# LB 17 258$B2 $CM* $SP* $B2; 259 260# 261# LB 18 Break after spaces. 262# 263$LB18NonBreaks = [$LB8NonBreaks - [$SP]]; 264$LB18Breaks = [$LB8Breaks $SP]; 265 266 267# LB 19 268# x QU 269$LB18NonBreaks $CM* $QU; 270^$CM+ $QU; 271 272# QU x 273$QU $CM* .; 274 275# LB 20 276# <break> $CB 277# $CB <break> 278# 279$LB20NonBreaks = [$LB18NonBreaks - $CB]; 280 281# LB 20.09 Don't break between Hyphens and Letters when there is a break preceding the hyphen. 282# Originally added as a Finnish tailoring, now promoted to default ICU behavior. 283# Note: this is not default UAX-14 behaviour. See issue ICU-8151. 284# 285^($HY | $HH) $CM* $ALPlus; 286 287# LB 21 x (BA | HY | NS) 288# BB x 289# 290$LB20NonBreaks $CM* ($BA | $HY | $NS); 291 292 293^$CM+ ($BA | $HY | $NS); 294 295$BB $CM* [^$CB]; # $BB x 296$BB $CM* $LB20NonBreaks; 297 298# LB 21a Don't break after Hebrew + Hyphen 299# HL (HY | BA) x 300# 301$HL $CM* ($HY | $BA) $CM* [^$CB]?; 302 303# LB 21b (forward) Don't break between SY and HL 304# (break between HL and SY already disallowed by LB 13 above) 305$SY $CM* $HL; 306 307# LB 22 Do not break before ellipses 308# 309$LB20NonBreaks $CM* $IN; 310^$CM+ $IN; 311 312 313# LB 23 314# 315($ALPlus | $HL) $CM* $NU; 316^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL 317$NU $CM* ($ALPlus | $HL); 318 319# LB 23a 320# 321$PR $CM* ($ID | $EB | $EM); 322($ID | $EB | $EM) $CM* $PO; 323 324 325# 326# LB 24 327# 328($PR | $PO) $CM* ($ALPlus | $HL); 329($ALPlus | $HL) $CM* ($PR | $PO); 330^$CM+ ($PR | $PO); # Rule 10, any otherwise unattached CM behaves as AL 331 332# 333# LB 25 Numbers. 334# 335(($PR | $PO) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))* 336 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?; 337 338# LB 26 Do not break a Korean syllable 339# 340$JL $CM* ($JL | $JV | $H2 | $H3); 341($JV | $H2) $CM* ($JV | $JT); 342($JT | $H3) $CM* $JT; 343 344# LB 27 Treat korean Syllable Block the same as ID (don't break it) 345($JL | $JV | $JT | $H2 | $H3) $CM* $PO; 346$PR $CM* ($JL | $JV | $JT | $H2 | $H3); 347 348 349# LB 28 Do not break between alphabetics 350# 351($ALPlus | $HL) $CM* ($ALPlus | $HL); 352^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL 353 354# LB 29 355$IS $CM* ($ALPlus | $HL); 356 357# LB 30 358($ALPlus | $HL | $NU) $CM* $OP30; 359^$CM+ $OP30; # The $CM+ is from rule 10, an unattached CM is treated as AL. 360$CP30 $CM* ($ALPlus | $HL | $NU); 361 362# LB 30a Do not break between regional indicators. Break after pairs of them. 363# Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM. 364$RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $CM]]; 365$RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $CM]]; 366$RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $ZWJ {eof}]; 367# note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?' 368# because of the chain-out behavior difference. The rule must chain out only from the [set characters], 369# not from the preceding $RI or $CM, which it would be able to do if the set were optional. 370 371# LB30b Do not break between an emoji base (or potential emoji) and an emoji modifier. 372$EB $CM* $EM; 373$ExtPictUnassigned $CM* $EM; 374 375# LB 31 Break everywhere else. 376# Match a single code point if no other rule applies. 377.; 378