tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

line_cj.txt (14102B)


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