Home | History | Annotate | Download | only in rules
      1 #
      2 #   Copyright (C) 2016 and later: Unicode, Inc. and others.
      3 #   License & terms of use: http://www.unicode.org/copyright.html
      4 #   Copyright (C) 2002-2016, International Business Machines Corporation and others.
      5 #       All Rights Reserved.
      6 #
      7 #   file:  char.txt
      8 #
      9 #   ICU Character Break Rules, also known as Grapheme Cluster Boundaries
     10 #      See Unicode Standard Annex #29.
     11 #      These rules are based on UAX #29 Revision 29 for Unicode Version 9.0
     12 #      plus proposed updates for Emoji 4.0 from https://goo.gl/cluFCn
     13 
     14 #
     15 #  Character Class Definitions.
     16 #
     17 $CR          = [\p{Grapheme_Cluster_Break = CR}];
     18 $LF          = [\p{Grapheme_Cluster_Break = LF}];
     19 $Control     = [[\p{Grapheme_Cluster_Break = Control}]];
     20 $Extend      = [[\p{Grapheme_Cluster_Break = Extend}]];
     21 $ZWJ         = [\p{Grapheme_Cluster_Break = ZWJ}];
     22 $Regional_Indicator = [\p{Grapheme_Cluster_Break = Regional_Indicator}];
     23 $Prepend     = [\p{Grapheme_Cluster_Break = Prepend}];
     24 $SpacingMark = [\p{Grapheme_Cluster_Break = SpacingMark}];
     25 
     26 #
     27 # Korean Syllable Definitions
     28 #
     29 $L           = [\p{Grapheme_Cluster_Break = L}];
     30 $V           = [\p{Grapheme_Cluster_Break = V}];
     31 $T           = [\p{Grapheme_Cluster_Break = T}];
     32 
     33 $LV          = [\p{Grapheme_Cluster_Break = LV}];
     34 $LVT         = [\p{Grapheme_Cluster_Break = LVT}];
     35 
     36 # Emoji defintions
     37 
     38 $E_Base      = [[\p{Grapheme_Cluster_Break = EB}] \U0001F3C2\U0001F3C7\U0001F3CC\U0001F46A-\U0001F46D\U0001F46F\U0001F574\U0001F6CC];
     39 $E_Modifier  = [\p{Grapheme_Cluster_Break = EM}];
     40 
     41 # Data for Extended Pictographic scraped from CLDR common/properties/ExtendedPictographic.txt, r12773
     42 $Extended_Pict = [\U0001F774-\U0001F77F\u2700-\u2701\u2703-\u2704\u270E\u2710-\u2711\u2765-\u2767\U0001F030-\U0001F093\U0001F094-\U0001F09F\U0001F10D-\U0001F10F\U0001F12F\U0001F16C-\U0001F16F\U0001F1AD-\U0001F1E5\U0001F203-\U0001F20F\U0001F23C-\U0001F23F\U0001F249-\U0001F24F\U0001F252-\U0001F2FF\U0001F7D5-\U0001F7FF\U0001F000-\U0001F003\U0001F005-\U0001F02B\U0001F02C-\U0001F02F\U0001F322-\U0001F323\U0001F394-\U0001F395\U0001F398\U0001F39C-\U0001F39D\U0001F3F1-\U0001F3F2\U0001F3F6\U0001F4FE\U0001F53E-\U0001F548\U0001F54F\U0001F568-\U0001F56E\U0001F571-\U0001F572\U0001F57B-\U0001F586\U0001F588-\U0001F589\U0001F58E-\U0001F58F\U0001F591-\U0001F594\U0001F597-\U0001F5A3\U0001F5A6-\U0001F5A7\U0001F5A9-\U0001F5B0\U0001F5B3-\U0001F5BB\U0001F5BD-\U0001F5C1\U0001F5C5-\U0001F5D0\U0001F5D4-\U0001F5DB\U0001F5DF-\U0001F5E0\U0001F5E2\U0001F5E4-\U0001F5E7\U0001F5E9-\U0001F5EE\U0001F5F0-\U0001F5F2\U0001F5F4-\U0001F5F9\u2605\u2607-\u260D\u260F-\u2610\u2612\u2616-\u2617\u2619-\u261C\u261E-\u261F\u2621\u2624-\u2625\u2627-\u2629\u262B-\u262D\u2630-\u2637\u263B-\u2647\u2654-\u265F\u2661-\u2662\u2664\u2667\u2669-\u267A\u267C-\u267E\u2680-\u2691\u2695\u2698\u269A\u269D-\u269F\u26A2-\u26A9\u26AC-\u26AF\u26B2-\u26BC\u26BF-\u26C3\u26C6-\u26C7\u26C9-\u26CD\u26D0\u26D2\u26D5-\u26E8\u26EB-\u26EF\u26F6\u26FB-\u26FC\u26FE-\u26FF\u2388\U0001FA00-\U0001FFFD\U0001F0A0-\U0001F0AE\U0001F0B1-\U0001F0BF\U0001F0C1-\U0001F0CF\U0001F0D1-\U0001F0F5\U0001F0AF-\U0001F0B0\U0001F0C0\U0001F0D0\U0001F0F6-\U0001F0FF\U0001F80C-\U0001F80F\U0001F848-\U0001F84F\U0001F85A-\U0001F85F\U0001F888-\U0001F88F\U0001F8AE-\U0001F8FF\U0001F900-\U0001F90F\U0001F91F\U0001F928-\U0001F92F\U0001F931-\U0001F932\U0001F93F\U0001F94C-\U0001F94F\U0001F95F-\U0001F97F\U0001F992-\U0001F9BF\U0001F9C1-\U0001F9FF\U0001F6C6-\U0001F6CA\U0001F6E6-\U0001F6E8\U0001F6EA\U0001F6F1-\U0001F6F2\U0001F6D3-\U0001F6DF\U0001F6ED-\U0001F6EF\U0001F6F7-\U0001F6FF];
     43 $E_Base_GAZ  = [\p{Grapheme_Cluster_Break = EBG}];
     44 $EmojiNRK    = [[\p{Emoji}] - [\p{Grapheme_Cluster_Break = Regional_Indicator}*\u00230-9]];
     45 
     46 ## -------------------------------------------------
     47 !!chain;
     48 !!lookAheadHardBreak;
     49 !!forward;
     50 
     51 $CR $LF;
     52 
     53 $L ($L | $V | $LV | $LVT);
     54 ($LV | $V) ($V | $T);
     55 ($LVT | $T) $T;
     56 
     57 # GB 9
     58 [^$Control $CR $LF] ($Extend | $ZWJ);
     59 
     60 # GB 9a (only for extended grapheme clusters)
     61 [^$Control $CR $LF] $SpacingMark;
     62 
     63 # GB 9b
     64 $Prepend [^$Control $CR $LF];
     65 
     66 # GB 10 Do not break within emoji modifier sequences or emoji zwj sequences.
     67 ($E_Base | $E_Base_GAZ) $Extend* $E_Modifier;
     68 
     69 # GB 11
     70 ($Extended_Pict | $EmojiNRK) $ZWJ ($Extended_Pict | $EmojiNRK);
     71 
     72 # GB 12-13. Keep pairs of regional indicators together
     73 #           Note that hard break '/' rule triggers only if there are three or more initial RIs,
     74 
     75 ^$Prepend* $Regional_Indicator $Regional_Indicator / $Regional_Indicator;
     76 ^$Prepend* $Regional_Indicator $Regional_Indicator;
     77 
     78 ## -------------------------------------------------
     79 
     80 !!reverse;
     81 $LF $CR;
     82 ($L | $V | $LV | $LVT) $L;
     83 ($V | $T) ($LV | $V);
     84 $T ($LVT | $T);
     85 
     86 # GB 9
     87 ($Extend | $ZWJ)   [^$Control $CR $LF];    #note that this will chain into Regional_Indicator when needed.
     88 
     89 # GB 9a
     90 $SpacingMark [^$Control $CR $LF];
     91 
     92 # GB 9b
     93 [^$Control $CR $LF] $Prepend;
     94 
     95 # GB 10
     96 $E_Modifier $Extend* ($E_Base | $E_Base_GAZ);
     97 
     98 # GB 11 Don't break between ZWJ and Glue_After_ZWJ
     99 ($Extended_Pict | $EmojiNRK) $ZWJ ($Extended_Pict | $EmojiNRK);
    100 
    101 # GB 12-13. Going backwards, we must scan through any number of regional indicators as pairs.
    102 #
    103 [{bof} $Extend $ZWJ $SpacingMark] $Regional_Indicator $Regional_Indicator / ($Regional_Indicator $Regional_Indicator)+ [{eof}[^$Regional_Indicator]];
    104 [{bof} $Extend $ZWJ $SpacingMark]                     $Regional_Indicator / ($Regional_Indicator $Regional_Indicator)+ [{eof}[^$Regional_Indicator]];
    105 $Regional_Indicator $Regional_Indicator;
    106 $Regional_Indicator $Prepend;
    107 
    108 ## -------------------------------------------------
    109 
    110 !!safe_reverse;
    111 $Regional_Indicator $Regional_Indicator;
    112 ($Extend | $ZWJ | $EmojiNRK | $Extended_Pict)+ .;
    113 
    114 ## -------------------------------------------------
    115 
    116 !!safe_forward;
    117 $Regional_Indicator $Regional_Indicator;
    118 ($Extend | $ZWJ | $EmojiNRK | $Extended_Pict)+ .;
    119