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 Revision 44 for Unicode 13.0 11# http://www.unicode.org/reports/tr14/, 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 hyphens 2010 & 2013 (both BA) and 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$AL = [:LineBreak = Alphabetic:]; 32$BAX = [\u2010 \u2013]; 33$BA = [[:LineBreak = Break_After:] - $BAX]; 34$HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA. 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:] \u201d]; 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$NSX = [\u301C \u30A0]; 62$NS = [[:LineBreak = Nonstarter:] - $NSX]; 63$NU = [:LineBreak = Numeric:]; 64$OP = [[:LineBreak = Open_Punctuation:] \u201c]; 65$PO = [:LineBreak = Postfix_Numeric:]; 66$PR = [:LineBreak = Prefix_Numeric:]; 67$QU = [[:LineBreak = Quotation:] - [\u201c\u201d]]; 68$RI = [:LineBreak = Regional_Indicator:]; 69$SA = [:LineBreak = Complex_Context:]; 70$SG = [:LineBreak = Surrogate:]; 71$SP = [:LineBreak = Space:]; 72$SY = [:LineBreak = Break_Symbols:]; 73$WJ = [:LineBreak = Word_Joiner:]; 74$XX = [:LineBreak = Unknown:]; 75$ZW = [:LineBreak = ZWSpace:]; 76$ZWJ = [:LineBreak = ZWJ:]; 77 78# OP30 and CP30 are variants of OP and CP that appear in-line in rule LB30 from UAX 14, 79# without a formal name. Because ICU rules require multiple uses of the expressions, 80# give them a single definition with a name 81 82$OP30 = [$OP - [\p{ea=F}\p{ea=W}\p{ea=H}]]; 83$CP30 = [$CP - [\p{ea=F}\p{ea=W}\p{ea=H}]]; 84 85# By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly 86# list it in the numerous rules that use CM. 87# By LB1, SA characters with general categor of Mn or Mc also resolve to CM. 88 89$CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]]; 90$CMX = [[$CM] - [$ZWJ]]; 91 92# Dictionary character set, for triggering language-based break engines. Currently 93# limited to LineBreak=Complex_Context (SA). 94 95$dictionary = [$SA]; 96 97# 98# Rule LB1. By default, treat AI (characters with ambiguous east Asian width), 99# SA (Dictionary chars, excluding Mn and Mc) 100# SG (Unpaired Surrogates) 101# XX (Unknown, unassigned) 102# as $AL (Alphabetic) 103# 104$ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]]; 105 106 107## ------------------------------------------------- 108 109# 110# CAN_CM is the set of characters that may combine with CM combining chars. 111# Note that Linebreak UAX 14's concept of a combining char and the rules 112# for what they can combine with are _very_ different from the rest of Unicode. 113# 114# Note that $CM itself is left out of this set. If CM is needed as a base 115# it must be listed separately in the rule. 116# 117$CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs 118$CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs 119 120# 121# AL_FOLLOW set of chars that can unconditionally follow an AL 122# Needed in rules where stand-alone $CM s are treated as AL. 123# 124$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]; 125 126 127# 128# Rule LB 4, 5 Mandatory (Hard) breaks. 129# 130$LB4Breaks = [$BK $CR $LF $NL]; 131$LB4NonBreaks = [^$BK $CR $LF $NL $CM]; 132$CR $LF {100}; 133 134# 135# LB 6 Do not break before hard line breaks. 136# 137$LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks. 138$CAN_CM $CM* $LB4Breaks {100}; 139^$CM+ $LB4Breaks {100}; 140 141# LB 7 x SP 142# x ZW 143$LB4NonBreaks [$SP $ZW]; 144$CAN_CM $CM* [$SP $ZW]; 145^$CM+ [$SP $ZW]; 146 147# 148# LB 8 Break after zero width space 149# ZW SP* ÷ 150# 151$LB8Breaks = [$LB4Breaks $ZW]; 152$LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]]; 153$ZW $SP* / [^$SP $ZW $LB4Breaks]; 154 155# LB 8a ZWJ x Do not break Emoji ZWJ sequences. 156# 157$ZWJ [^$CM]; 158 159# LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL 160# $CM not covered by the above needs to behave like $AL 161# See definition of $CAN_CM. 162 163$CAN_CM $CM+; # Stick together any combining sequences that don't match other rules. 164^$CM+; 165 166# 167# LB 11 Do not break before or after WORD JOINER & related characters. 168# 169$CAN_CM $CM* $WJ; 170$LB8NonBreaks $WJ; 171^$CM+ $WJ; 172 173$WJ $CM* .; 174 175# 176# LB 12 Do not break after NBSP and related characters. 177# GL x 178# 179$GL $CM* .; 180 181# 182# LB 12a Do not break before NBSP and related characters ... 183# [^SP BA HY] x GL 184# 185[[$LB8NonBreaks] - [$SP $BA $BAX $HY]] $CM* $GL; 186^$CM+ $GL; 187 188 189 190 191# LB 13 Don't break before ']' or '!' or or '/', even after spaces. 192# 193$LB8NonBreaks $CL; 194$CAN_CM $CM* $CL; 195^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL 196 197$LB8NonBreaks $CP; 198$CAN_CM $CM* $CP; 199^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL 200 201$LB8NonBreaks $EX; 202$CAN_CM $CM* $EX; 203^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL 204 205$LB8NonBreaks $SY; 206$CAN_CM $CM* $SY; 207^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL 208 209 210# 211# LB 14 Do not break after OP, even after spaces 212# Note subtle interaction with "SP IS /" rules in LB14a. 213# This rule consumes the SP, chaining happens on the IS, effectivley overriding the SP IS rules, 214# which is the desired behavior. 215# 216$OP $CM* $SP* .; 217 218$OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL 219 # by rule 8, CM following a SP is stand-alone. 220 221 222# LB 14a Force a break before start of a number with a leading decimal pt, e.g. " .23" 223# Note: would be simpler to express as "$SP / $IS $CM* $NU;", but ICU rules have limitations. 224# See issue ICU-20303 225 226 227$CanFollowIS = [$BK $CR $LF $NL $SP $ZW $WJ $GL $CL $CP $EX $IS $SY $QU $BA $HY $NS $ALPlus $HL $IN]; 228$SP $IS / [^ $CanFollowIS $NU $CM]; 229$SP $IS $CM* $CMX / [^ $CanFollowIS $NU $CM]; 230 231# 232# LB 14b Do not break before numeric separators (IS), even after spaces. 233 234[$LB8NonBreaks - $SP] $IS; 235$SP $IS $CM* [$CanFollowIS {eof}]; 236$SP $IS $CM* $ZWJ [^$CM $NU]; 237 238$CAN_CM $CM* $IS; 239^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL 240 241 242# LB 15 243$QU $CM* $SP* $OP; 244 245# LB 16 246# Do not break between closing punctuation and $NS, even with intervening spaces 247# But DO allow a break between closing punctuation and $NSX, don't include it here 248($CL | $CP) $CM* $SP* $NS; 249 250# LB 17 251$B2 $CM* $SP* $B2; 252 253# 254# LB 18 Break after spaces. 255# 256$LB18NonBreaks = [$LB8NonBreaks - [$SP]]; 257$LB18Breaks = [$LB8Breaks $SP]; 258 259 260# LB 19 261# x QU 262$LB18NonBreaks $CM* $QU; 263^$CM+ $QU; 264 265# QU x 266$QU $CM* .; 267 268# LB 20 269# <break> $CB 270# $CB <break> 271# 272$LB20NonBreaks = [$LB18NonBreaks - $CB]; 273 274# LB 20.09 Don't break between Hyphens and Letters when there is a break preceding the hyphen. 275# Originally added as a Finnish tailoring, now promoted to default ICU behavior. 276# Note: this is not default UAX-14 behaviour. See issue ICU-8151. 277# 278^($HY | $HH) $CM* $ALPlus; 279 280# LB 21 x (BA | HY | NS) 281# BB x 282# 283# DO allow breaks here before $BAX and $NSX, so don't include them 284$LB20NonBreaks $CM* ($BA | $HY | $NS); 285 286 287^$CM+ ($BA | $HY | $NS); 288 289$BB $CM* [^$CB]; # $BB x 290$BB $CM* $LB20NonBreaks; 291 292# LB 21a Don't break after Hebrew + Hyphen 293# HL (HY | BA) x 294# 295$HL $CM* ($HY | $BA | $BAX) $CM* [^$CB]?; 296 297# LB 21b (forward) Don't break between SY and HL 298# (break between HL and SY already disallowed by LB 13 above) 299$SY $CM* $HL; 300 301# LB 22 Do not break before ellipses 302# 303$LB20NonBreaks $CM* $IN; 304^$CM+ $IN; 305 306 307# LB 23 308# 309($ALPlus | $HL) $CM* $NU; 310^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL 311$NU $CM* ($ALPlus | $HL); 312 313# LB 23a 314# 315$PR $CM* ($ID | $EB | $EM); 316($ID | $EB | $EM) $CM* $PO; 317 318 319# 320# LB 24 321# 322($PR | $PO) $CM* ($ALPlus | $HL); 323($ALPlus | $HL) $CM* ($PR | $PO); 324^$CM+ ($PR | $PO); # Rule 10, any otherwise unattached CM behaves as AL 325 326# 327# LB 25 Numbers. 328# 329(($PR | $PO) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))* 330 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?; 331 332# LB 26 Do not break a Korean syllable 333# 334$JL $CM* ($JL | $JV | $H2 | $H3); 335($JV | $H2) $CM* ($JV | $JT); 336($JT | $H3) $CM* $JT; 337 338# LB 27 Treat korean Syllable Block the same as ID (don't break it) 339($JL | $JV | $JT | $H2 | $H3) $CM* $IN; 340($JL | $JV | $JT | $H2 | $H3) $CM* $PO; 341$PR $CM* ($JL | $JV | $JT | $H2 | $H3); 342 343 344# LB 28 Do not break between alphabetics 345# 346($ALPlus | $HL) $CM* ($ALPlus | $HL); 347^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL 348 349# LB 29 350$IS $CM* ($ALPlus | $HL); 351 352# LB 30 353($ALPlus | $HL | $NU) $CM* $OP30; 354^$CM+ $OP30; # The $CM+ is from rule 10, an unattached CM is treated as AL. 355$CP30 $CM* ($ALPlus | $HL | $NU); 356 357# LB 30a Do not break between regional indicators. Break after pairs of them. 358# Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM. 359$RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $CM]]; 360$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]]; 361$RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $ZWJ {eof}]; 362# note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?' 363# because of the chain-out behavior difference. The rule must chain out only from the [set characters], 364# not from the preceding $RI or $CM, which it would be able to do if the set were optional. 365 366# LB 30b Do not break between an Emoji Base and an Emoji Modifier 367$EB $CM* $EM; 368 369# LB 31 Break everywhere else. 370# Match a single code point if no other rule applies. 371.; 372