• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5# and others. All Rights Reserved.
6#
7# file:  word.txt
8#
9# ICU Word Break Rules
10#      See Unicode Standard Annex #29.
11#      These rules are based on UAX #29 Revision 29 for Unicode Version 9.0
12#      with additions for Emoji Sequences from https://goo.gl/cluFCn
13#
14# Note:  Updates to word.txt will usually need to be merged into
15#        word_POSIX.txt also.
16
17##############################################################################
18#
19#  Character class definitions from TR 29
20#
21##############################################################################
22
23!!chain;
24
25
26#
27#  Character Class Definitions.
28#
29
30$CR                 = [\p{Word_Break = CR}];
31$LF                 = [\p{Word_Break = LF}];
32$Newline            = [\p{Word_Break = Newline} ];
33$Extend             = [\p{Word_Break = Extend}];
34$ZWJ                = [\p{Word_Break = ZWJ}];
35$Regional_Indicator = [\p{Word_Break = Regional_Indicator}];
36$Format             = [\p{Word_Break = Format}];
37$Katakana           = [\p{Word_Break = Katakana}];
38$Hebrew_Letter      = [\p{Word_Break = Hebrew_Letter}];
39$ALetter            = [\p{Word_Break = ALetter}];
40$Single_Quote       = [\p{Word_Break = Single_Quote}];
41$Double_Quote       = [\p{Word_Break = Double_Quote}];
42$MidNumLet          = [\p{Word_Break = MidNumLet}];
43$MidLetter          = [\p{Word_Break = MidLetter}];
44$MidNum             = [\p{Word_Break = MidNum}];
45$Numeric            = [\p{Word_Break = Numeric}];
46$ExtendNumLet       = [\p{Word_Break = ExtendNumLet}];
47$E_Base             = [\p{Word_Break = EB}\U0001F3C2\U0001F3C7\U0001F3CC\U0001F46A-\U0001F46D\U0001F46F\U0001F574\U0001F6CC];
48$E_Modifier         = [\p{Word_Break = EM}];
49
50# Data for Extended Pictographic scraped from CLDR common/properties/ExtendedPictographic.txt, r12773
51$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];
52$EBG                = [\p{Word_Break = EBG}];
53$EmojiNRK           = [[\p{Emoji}] - [\p{Word_Break = Regional_Indicator}\u002a\u00230-9©®™〰〽]];
54
55$Han                = [:Han:];
56$Hiragana           = [:Hiragana:];
57
58
59#   Dictionary character set, for triggering language-based break engines. Currently
60#   limited to LineBreak=Complex_Context. Note that this set only works in Unicode
61#   5.0 or later as the definition of Complex_Context was corrected to include all
62#   characters requiring dictionary break.
63
64$Control        = [\p{Grapheme_Cluster_Break = Control}];
65$HangulSyllable = [\uac00-\ud7a3];
66$ComplexContext = [:LineBreak = Complex_Context:];
67$KanaKanji      = [$Han $Hiragana $Katakana];
68$dictionaryCJK  = [$KanaKanji $HangulSyllable];
69$dictionary     = [$ComplexContext $dictionaryCJK];
70
71# leave CJK scripts out of ALetterPlus
72$ALetterPlus  = [$ALetter-$dictionaryCJK [$ComplexContext-$Extend-$Control]];
73
74
75#
76#  Rules 4    Ignore Format and Extend characters,
77#             except when they appear at the beginning of a region of text.
78#
79# TODO: check if handling of katakana in dictionary makes rules incorrect/void
80$KatakanaEx           = $Katakana           ($Extend |  $Format | $ZWJ)*;
81$Hebrew_LetterEx      = $Hebrew_Letter      ($Extend |  $Format | $ZWJ)*;
82$ALetterEx            = $ALetterPlus        ($Extend |  $Format | $ZWJ)*;
83$Single_QuoteEx       = $Single_Quote       ($Extend |  $Format | $ZWJ)*;
84$Double_QuoteEx       = $Double_Quote       ($Extend |  $Format | $ZWJ)*;
85$MidNumLetEx          = $MidNumLet          ($Extend |  $Format | $ZWJ)*;
86$MidLetterEx          = $MidLetter          ($Extend |  $Format | $ZWJ)*;
87$MidNumEx             = $MidNum             ($Extend |  $Format | $ZWJ)*;
88$NumericEx            = $Numeric            ($Extend |  $Format | $ZWJ)*;
89$ExtendNumLetEx       = $ExtendNumLet       ($Extend |  $Format | $ZWJ)*;
90$Regional_IndicatorEx = $Regional_Indicator ($Extend |  $Format | $ZWJ)*;
91
92$Ideographic    = [\p{Ideographic}];
93$HiraganaEx     = $Hiragana     ($Extend |  $Format | $ZWJ)*;
94$IdeographicEx  = $Ideographic  ($Extend |  $Format | $ZWJ)*;
95
96## -------------------------------------------------
97
98!!forward;
99
100
101# Rule 3 - CR x LF
102#
103$CR $LF;
104
105# Rule 3c   ZWJ x (Extended_Pict | EmojiNRK).  Precedes WB4, so no intervening Extend chars allowed.
106#
107$ZWJ ($Extended_Pict | $EmojiNRK);
108
109
110# Rule 4 - ignore Format and Extend characters, except when they appear at the beginning
111#          of a region of Text.   The rule here comes into play when the start of text
112#          begins with a group of Format chars, or with a "word" consisting of a single
113#          char that is not in any of the listed word break categories followed by
114#          format char(s), or is not a CJK dictionary character.
115[^$CR $LF $Newline]? ($Extend |  $Format | $ZWJ)+;
116
117$NumericEx {100};
118$ALetterEx {200};
119$HangulSyllable {200};
120$Hebrew_LetterEx{200};
121$KatakanaEx {400};       # note:  these status values override those from rule 5
122$HiraganaEx {400};       #        by virtue of being numerically larger.
123$IdeographicEx {400};    #
124
125$E_Base ($Extend | $Format | $ZWJ)*;
126$E_Modifier ($Extend | $Format | $ZWJ)*;
127$Extended_Pict ($Extend | $Format | $ZWJ)*;
128
129#
130# rule 5
131#    Do not break between most letters.
132#
133($ALetterEx | $Hebrew_LetterEx)  ($ALetterEx | $Hebrew_LetterEx) {200};
134
135# rule 6 and 7
136($ALetterEx | $Hebrew_LetterEx) ($MidLetterEx | $MidNumLetEx | $Single_QuoteEx) ($ALetterEx | $Hebrew_LetterEx) {200};
137
138# rule 7a
139$Hebrew_LetterEx $Single_QuoteEx {200};
140
141# rule 7b and 7c
142$Hebrew_LetterEx $Double_QuoteEx $Hebrew_LetterEx {200};
143
144# rule 8
145
146$NumericEx $NumericEx {100};
147
148# rule 9
149
150($ALetterEx | $Hebrew_LetterEx) $NumericEx {200};
151
152# rule 10
153
154$NumericEx ($ALetterEx | $Hebrew_LetterEx) {200};
155
156# rule 11 and 12
157
158$NumericEx ($MidNumEx | $MidNumLetEx | $Single_QuoteEx) $NumericEx {100};
159
160# rule 13
161# to be consistent with $KanaKanji $KanaKanhi, changed
162# from 300 to 400.
163# See also TestRuleStatus in intltest/rbbiapts.cpp
164$KatakanaEx  $KatakanaEx {400};
165
166# rule 13a/b
167
168$ALetterEx       $ExtendNumLetEx {200};    #  (13a)
169$Hebrew_LetterEx $ExtendNumLetEx {200};    #  (13a)
170$NumericEx       $ExtendNumLetEx {100};    #  (13a)
171$KatakanaEx      $ExtendNumLetEx {400};    #  (13a)
172$ExtendNumLetEx  $ExtendNumLetEx {200};    #  (13a)
173
174$ExtendNumLetEx  $ALetterEx      {200};    #  (13b)
175$ExtendNumLetEx  $Hebrew_Letter  {200};    #  (13b)
176$ExtendNumLetEx  $NumericEx      {100};    #  (13b)
177$ExtendNumLetEx  $KatakanaEx     {400};    #  (13b)
178
179# rule 14
180#    Do not break within emoji modifier sequences
181
182($E_Base | $EBG) ($Format | $Extend | $ZWJ)* $E_Modifier;
183
184# rules 15 - 17
185#    Pairs of Regional Indicators stay together.
186#    With rule chaining disabled by ^, this rule will match exactly two of them.
187#    No other rule begins with a Regional_Indicator, so chaining cannot extend the match.
188#
189^$Regional_IndicatorEx $Regional_IndicatorEx;
190
191# special handling for CJK characters: chain for later dictionary segmentation
192$HangulSyllable $HangulSyllable {200};
193$KanaKanji $KanaKanji {400}; # different rule status if both kana and kanji found
194
195
196## -------------------------------------------------
197
198!!reverse;
199
200$BackHebrew_LetterEx      = ($Format | $Extend | $ZWJ)* $Hebrew_Letter;
201$BackALetterEx            = ($Format | $Extend | $ZWJ)* $ALetterPlus;
202$BackSingle_QuoteEx       = ($Format | $Extend | $ZWJ)* $Single_Quote;
203$BackDouble_QuoteEx       = ($Format | $Extend | $ZWJ)* $Double_Quote;
204$BackMidNumLetEx          = ($Format | $Extend | $ZWJ)* $MidNumLet;
205$BackNumericEx            = ($Format | $Extend | $ZWJ)* $Numeric;
206$BackMidNumEx             = ($Format | $Extend | $ZWJ)* $MidNum;
207$BackMidLetterEx          = ($Format | $Extend | $ZWJ)* $MidLetter;
208$BackKatakanaEx           = ($Format | $Extend | $ZWJ)* $Katakana;
209$BackHiraganaEx           = ($Format | $Extend | $ZWJ)* $Hiragana;
210$BackExtendNumLetEx       = ($Format | $Extend | $ZWJ)* $ExtendNumLet;
211$BackRegional_IndicatorEx = ($Format | $Extend | $ZWJ)* $Regional_Indicator;
212
213# rule 3
214$LF $CR;
215
216# Rule 3c   ZWJ x (Extended_Pict | EmojiNRK).  Precedes WB4, so no intervening Extend chars allowed.
217#
218($Extended_Pict | $EmojiNRK) $ZWJ;
219
220# rule 4
221($Format | $Extend | $ZWJ)*  [^$CR $LF $Newline]?;
222
223# rule 5
224
225($BackALetterEx | $BackHebrew_LetterEx) ($BackALetterEx | $BackHebrew_LetterEx);
226
227# rule 6 and 7
228
229($BackALetterEx | $BackHebrew_LetterEx) ($BackMidLetterEx | $BackMidNumLetEx | $BackSingle_QuoteEx) ($BackALetterEx | $BackHebrew_LetterEx);
230
231# rule 7a
232$BackSingle_QuoteEx $BackHebrew_LetterEx;
233
234# Rule 7b and 7c
235$BackHebrew_LetterEx $BackDouble_QuoteEx $BackHebrew_LetterEx;
236
237# rule 8
238
239$BackNumericEx $BackNumericEx;
240
241# rule 9
242
243$BackNumericEx ($BackALetterEx | $BackHebrew_LetterEx);
244
245# rule 10
246
247($BackALetterEx | $BackHebrew_LetterEx) $BackNumericEx;
248
249# rule 11 and 12
250
251$BackNumericEx ($BackMidNumEx | $BackMidNumLetEx | $BackSingle_QuoteEx) $BackNumericEx;
252
253# rule 13
254
255$BackKatakanaEx $BackKatakanaEx;
256
257# rules 13 a/b
258#
259$BackExtendNumLetEx ($BackALetterEx | $BackHebrew_LetterEx | $BackNumericEx | $BackKatakanaEx | $BackExtendNumLetEx);
260($BackALetterEx | $BackHebrew_LetterEx | $BackNumericEx | $BackKatakanaEx) $BackExtendNumLetEx;
261
262# special handling for CJK characters: chain for later dictionary segmentation
263$HangulSyllable $HangulSyllable;
264$KanaKanji $KanaKanji; #different rule status if both kanji and kana found
265
266# rule 14
267
268$E_Modifier ($Format | $Extend | $ZWJ)* ($E_Base | $EBG);
269
270# rule 15 - 17
271#    Pairs of Regional Indicators stay together.
272
273^$BackRegional_IndicatorEx / ($BackRegional_IndicatorEx $BackRegional_IndicatorEx)*
274        ($Format | $Extend | $ZWJ)* [[^$Regional_Indicator $Format $Extend $ZWJ] {eof}];
275^$BackRegional_IndicatorEx $BackRegional_IndicatorEx / ($BackRegional_IndicatorEx $BackRegional_IndicatorEx)*
276        ($Format | $Extend | $ZWJ)* [[^$Regional_Indicator $Format $Extend $ZWJ] {eof}];
277
278($Extended_Pict | $EmojiNRK) $ZWJ $BackRegional_IndicatorEx / ($BackRegional_IndicatorEx $BackRegional_IndicatorEx)*
279        ($Format | $Extend | $ZWJ)* [[^$Regional_Indicator $Format $Extend $ZWJ] {eof}];
280($Extended_Pict | $EmojiNRK) $ZWJ $BackRegional_IndicatorEx $BackRegional_IndicatorEx / ($BackRegional_IndicatorEx $BackRegional_IndicatorEx)*
281        ($Format | $Extend | $ZWJ)* [[^$Regional_Indicator $Format $Extend $ZWJ] {eof}];
282
283
284
285## -------------------------------------------------
286
287!!safe_reverse;
288
289# rule 3
290($Extend | $Format | $ZWJ)+ .?;
291
292# rule 6
293($MidLetter | $MidNumLet | $Single_Quote) ($BackALetterEx | $BackHebrew_LetterEx);
294
295# rule 7b
296$Double_Quote $BackHebrew_LetterEx;
297
298
299# rule 11
300($MidNum | $MidNumLet | $Single_Quote) $BackNumericEx;
301
302# rule 13c
303$BackRegional_IndicatorEx*;
304
305# For dictionary-based break
306$dictionary $dictionary;
307
308## -------------------------------------------------
309
310!!safe_forward;
311
312# rule 4
313($Extend | $Format | $ZWJ)+ .?;
314
315# rule 6
316($MidLetterEx | $MidNumLetEx | $Single_QuoteEx) ($ALetterEx | $Hebrew_LetterEx);
317
318# rule 7b
319$Double_QuoteEx $Hebrew_LetterEx;
320
321# rule 11
322($MidNumEx | $MidNumLetEx | $Single_QuoteEx) $NumericEx;
323
324# rule 13c
325$Regional_IndicatorEx*;
326
327# For dictionary-based break
328$dictionary $dictionary;
329