tor-browser

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

line_loose.txt (14572B)


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