]> git.saurik.com Git - apple/icu.git/blame - icuSources/data/brkitr/rules/line.txt
ICU-62107.0.1.tar.gz
[apple/icu.git] / icuSources / data / brkitr / rules / line.txt
CommitLineData
0f5d89e8 1# Copyright (C) 2016 and later: Unicode, Inc. and others.
f3c0d7a5 2# License & terms of use: http://www.unicode.org/copyright.html
2ca993e8 3# Copyright (c) 2002-2016 International Business Machines Corporation and
46f4442e
A
4# others. All Rights Reserved.
5#
6# file: line.txt
7#
8# Line Breaking Rules
2ca993e8 9# Implement default line breaking as defined by
0f5d89e8 10# Unicode Standard Annex #14 Revision 40 for Unicode 11.0
46f4442e 11# http://www.unicode.org/reports/tr14/
729e4ab9
A
12#
13# TODO: Rule LB 8 remains as it was in Unicode 5.2
14# This is only because of a limitation of ICU break engine implementation,
15# not because the older behavior is desirable.
08b89b0a
A
16#
17# This corresponds to CSS line-break=strict (BCP47 -u-lb-strict).
18# It sets characters of class CJ to behave like NS.
46f4442e
A
19
20#
21# Character Classes defined by TR 14.
22#
23
24!!chain;
0f5d89e8 25!!quoted_literals_only;
46f4442e 26
f3c0d7a5
A
27$AI = [:LineBreak = Ambiguous:];
28$AL = [:LineBreak = Alphabetic:];
46f4442e
A
29$BA = [:LineBreak = Break_After:];
30$BB = [:LineBreak = Break_Before:];
31$BK = [:LineBreak = Mandatory_Break:];
32$B2 = [:LineBreak = Break_Both:];
33$CB = [:LineBreak = Contingent_Break:];
4388f060 34$CJ = [:LineBreak = Conditional_Japanese_Starter:];
46f4442e 35$CL = [:LineBreak = Close_Punctuation:];
f3c0d7a5 36# $CM = [:LineBreak = Combining_Mark:];
729e4ab9 37$CP = [:LineBreak = Close_Parenthesis:];
46f4442e 38$CR = [:LineBreak = Carriage_Return:];
f3c0d7a5
A
39$EB = [[:LineBreak = EB:] \U0001F46A-\U0001F46D\U0001F46F\U0001F91D\U0001F93C];
40$EM = [:LineBreak = EM:];
46f4442e
A
41$EX = [:LineBreak = Exclamation:];
42$GL = [:LineBreak = Glue:];
4388f060 43$HL = [:LineBreak = Hebrew_Letter:];
46f4442e
A
44$HY = [:LineBreak = Hyphen:];
45$H2 = [:LineBreak = H2:];
46$H3 = [:LineBreak = H3:];
f3c0d7a5 47$ID = [:LineBreak = Ideographic:];
46f4442e
A
48$IN = [:LineBreak = Inseperable:];
49$IS = [:LineBreak = Infix_Numeric:];
50$JL = [:LineBreak = JL:];
51$JV = [:LineBreak = JV:];
52$JT = [:LineBreak = JT:];
53$LF = [:LineBreak = Line_Feed:];
54$NL = [:LineBreak = Next_Line:];
f3c0d7a5 55# NS includes CJ for CSS strict line breaking.
4388f060 56$NS = [[:LineBreak = Nonstarter:] $CJ];
46f4442e
A
57$NU = [:LineBreak = Numeric:];
58$OP = [:LineBreak = Open_Punctuation:];
59$PO = [:LineBreak = Postfix_Numeric:];
60$PR = [:LineBreak = Prefix_Numeric:];
61$QU = [:LineBreak = Quotation:];
51004dcb 62$RI = [:LineBreak = Regional_Indicator:];
46f4442e
A
63$SA = [:LineBreak = Complex_Context:];
64$SG = [:LineBreak = Surrogate:];
65$SP = [:LineBreak = Space:];
66$SY = [:LineBreak = Break_Symbols:];
67$WJ = [:LineBreak = Word_Joiner:];
68$XX = [:LineBreak = Unknown:];
69$ZW = [:LineBreak = ZWSpace:];
f3c0d7a5
A
70$ZWJ = [:LineBreak = ZWJ:];
71
0f5d89e8
A
72# The following classes are no longer needed for ICU rules but may
73# still be needed for WebKit rules in lineClasses.txt
74# $EmojiNRK = [[\p{Emoji}] - [$RI \u002a\u00230-9©®™〰〽]];
75# $Extended_Pict = [:ExtPict:];
f3c0d7a5
A
76
77# By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly
78# list it in the numerous rules that use CM.
79# By LB1, SA characters with general categor of Mn or Mc also resolve to CM.
80
81$CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]];
08b89b0a 82
46f4442e 83# Dictionary character set, for triggering language-based break engines. Currently
f3c0d7a5 84# limited to LineBreak=Complex_Context (SA).
46f4442e 85
f3c0d7a5 86$dictionary = [$SA];
46f4442e
A
87
88#
89# Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
f3c0d7a5 90# SA (Dictionary chars, excluding Mn and Mc)
46f4442e
A
91# SG (Unpaired Surrogates)
92# XX (Unknown, unassigned)
93# as $AL (Alphabetic)
94#
f3c0d7a5
A
95$ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]];
96
46f4442e
A
97
98## -------------------------------------------------
99
46f4442e
A
100#
101# CAN_CM is the set of characters that may combine with CM combining chars.
102# Note that Linebreak UAX 14's concept of a combining char and the rules
103# for what they can combine with are _very_ different from the rest of Unicode.
104#
105# Note that $CM itself is left out of this set. If CM is needed as a base
106# it must be listed separately in the rule.
107#
108$CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs
109$CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs
110
111#
112# AL_FOLLOW set of chars that can unconditionally follow an AL
113# Needed in rules where stand-alone $CM s are treated as AL.
46f4442e 114#
f3c0d7a5 115$AL_FOLLOW = [$BK $CR $LF $NL $ZW $SP $CL $CP $EX $HL $IS $SY $WJ $GL $OP $QU $BA $HY $NS $IN $NU $PR $PO $ALPlus];
46f4442e
A
116
117
118#
119# Rule LB 4, 5 Mandatory (Hard) breaks.
120#
121$LB4Breaks = [$BK $CR $LF $NL];
2ca993e8 122$LB4NonBreaks = [^$BK $CR $LF $NL $CM];
46f4442e
A
123$CR $LF {100};
124
125#
126# LB 6 Do not break before hard line breaks.
127#
128$LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
129$CAN_CM $CM* $LB4Breaks {100};
2ca993e8 130^$CM+ $LB4Breaks {100};
46f4442e
A
131
132# LB 7 x SP
133# x ZW
134$LB4NonBreaks [$SP $ZW];
135$CAN_CM $CM* [$SP $ZW];
2ca993e8 136^$CM+ [$SP $ZW];
46f4442e
A
137
138#
139# LB 8 Break after zero width space
729e4ab9
A
140# TODO: ZW SP* <break>
141# An engine change is required to write the reverse rule for this.
142# For now, leave the Unicode 5.2 rule, ZW <break>
46f4442e
A
143#
144$LB8Breaks = [$LB4Breaks $ZW];
145$LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
146
0f5d89e8 147# LB 8a ZWJ x Do not break Emoji ZWJ sequences.
2ca993e8 148#
0f5d89e8 149$ZWJ [^$CM];
46f4442e 150
2ca993e8
A
151# LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
152# $CM not covered by the above needs to behave like $AL
46f4442e
A
153# See definition of $CAN_CM.
154
155$CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
2ca993e8 156^$CM+;
46f4442e
A
157
158#
159# LB 11 Do not break before or after WORD JOINER & related characters.
160#
f3c0d7a5
A
161$CAN_CM $CM* $WJ;
162$LB8NonBreaks $WJ;
163^$CM+ $WJ;
46f4442e 164
f3c0d7a5 165$WJ $CM* .;
46f4442e
A
166
167#
168# LB 12 Do not break after NBSP and related characters.
169# GL x
170#
f3c0d7a5 171$GL $CM* .;
2ca993e8 172
46f4442e
A
173#
174# LB 12a Do not break before NBSP and related characters ...
175# [^SP BA HY] x GL
176#
f3c0d7a5
A
177[[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GL;
178^$CM+ $GL;
46f4442e
A
179
180
181
182#
183# LB 13 Don't break before ']' or '!' or ';' or '/', even after spaces.
184#
185$LB8NonBreaks $CL;
186$CAN_CM $CM* $CL;
2ca993e8 187^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
46f4442e 188
729e4ab9
A
189$LB8NonBreaks $CP;
190$CAN_CM $CM* $CP;
2ca993e8 191^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
729e4ab9 192
46f4442e
A
193$LB8NonBreaks $EX;
194$CAN_CM $CM* $EX;
2ca993e8 195^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
46f4442e
A
196
197$LB8NonBreaks $IS;
198$CAN_CM $CM* $IS;
2ca993e8 199^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
46f4442e
A
200
201$LB8NonBreaks $SY;
202$CAN_CM $CM* $SY;
2ca993e8 203^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
46f4442e
A
204
205
206#
207# LB 14 Do not break after OP, even after spaces
208#
f3c0d7a5 209$OP $CM* $SP* .;
46f4442e 210
f3c0d7a5
A
211$OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
212 # by rule 8, CM following a SP is stand-alone.
46f4442e
A
213
214# LB 15
f3c0d7a5 215$QU $CM* $SP* $OP;
46f4442e
A
216
217# LB 16
f3c0d7a5 218($CL | $CP) $CM* $SP* $NS;
46f4442e
A
219
220# LB 17
f3c0d7a5 221$B2 $CM* $SP* $B2;
46f4442e
A
222
223#
224# LB 18 Break after spaces.
225#
226$LB18NonBreaks = [$LB8NonBreaks - [$SP]];
227$LB18Breaks = [$LB8Breaks $SP];
228
229
230# LB 19
231# x QU
f3c0d7a5
A
232$LB18NonBreaks $CM* $QU;
233^$CM+ $QU;
46f4442e
A
234
235# QU x
f3c0d7a5 236$QU $CM* .;
46f4442e
A
237
238
239# LB 20
240# <break> $CB
241# $CB <break>
242
243$LB20NonBreaks = [$LB18NonBreaks - $CB];
244
245# LB 21 x (BA | HY | NS)
246# BB x
247#
f3c0d7a5
A
248$LB20NonBreaks $CM* ($BA | $HY | $NS);
249^$CM+ ($BA | $HY | $NS);
46f4442e 250
f3c0d7a5
A
251$BB $CM* [^$CB]; # $BB x
252$BB $CM* $LB20NonBreaks;
46f4442e 253
4388f060
A
254# LB 21a Don't break after Hebrew + Hyphen
255# HL (HY | BA) x
2ca993e8 256#
f3c0d7a5 257$HL $CM* ($HY | $BA) $CM* [^$CB]?;
4388f060 258
51004dcb
A
259# LB 21b (forward) Don't break between SY and HL
260# (break between HL and SY already disallowed by LB 13 above)
f3c0d7a5 261$SY $CM* $HL;
51004dcb 262
46f4442e 263# LB 22
f3c0d7a5
A
264($ALPlus | $HL) $CM* $IN;
265^$CM+ $IN; # by rule 10, any otherwise unattached CM behaves as AL
266$EX $CM* $IN;
267($ID | $EB | $EM) $CM* $IN;
268$IN $CM* $IN;
269$NU $CM* $IN;
46f4442e
A
270
271
272# $LB 23
f3c0d7a5
A
273#
274($ALPlus | $HL) $CM* $NU;
275^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL
276$NU $CM* ($ALPlus | $HL);
277
278# LB 23a
279#
280$PR $CM* ($ID | $EB | $EM);
281($ID | $EB | $EM) $CM* $PO;
282
46f4442e
A
283
284#
285# LB 24
286#
f3c0d7a5
A
287($PR | $PO) $CM* ($ALPlus | $HL);
288($ALPlus | $HL) $CM* ($PR | $PO);
289^$CM+ ($PR | $PO); # Rule 10, any otherwise unattached CM behaves as AL
46f4442e
A
290
291#
292# LB 25 Numbers.
293#
f3c0d7a5
A
294(($PR | $PO) $CM*)? (($OP | $HY) $CM*)? $NU ($CM* ($NU | $SY | $IS))*
295 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?;
46f4442e
A
296
297# LB 26 Do not break a Korean syllable
298#
f3c0d7a5
A
299$JL $CM* ($JL | $JV | $H2 | $H3);
300($JV | $H2) $CM* ($JV | $JT);
301($JT | $H3) $CM* $JT;
46f4442e
A
302
303# LB 27 Treat korean Syllable Block the same as ID (don't break it)
f3c0d7a5
A
304($JL | $JV | $JT | $H2 | $H3) $CM* $IN;
305($JL | $JV | $JT | $H2 | $H3) $CM* $PO;
306$PR $CM* ($JL | $JV | $JT | $H2 | $H3);
46f4442e
A
307
308
309# LB 28 Do not break between alphabetics
310#
f3c0d7a5
A
311($ALPlus | $HL) $CM* ($ALPlus | $HL);
312^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL
46f4442e
A
313
314# LB 29
f3c0d7a5 315$IS $CM* ($ALPlus | $HL);
46f4442e 316
729e4ab9 317# LB 30
f3c0d7a5
A
318($ALPlus | $HL | $NU) $CM* $OP;
319^$CM+ $OP; # The $CM+ is from rule 10, an unattached CM is treated as AL.
320$CP $CM* ($ALPlus | $HL | $NU);
729e4ab9 321
2ca993e8 322# LB 30a Do not break between regional indicators. Break after pairs of them.
0f5d89e8
A
323# Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM.
324$RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
325$RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM]];
326$RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $ZWJ {eof}];
327# note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?'
328# because of the chain-out behavior difference. The rule must chain out only from the [set characters],
329# not from the preceding $RI or $CM, which it would be able to do if the set were optional.
2ca993e8
A
330
331# LB 30b Do not break between an Emoji Base and an Emoji Modifier
332$EB $CM* $EM;
08b89b0a 333
0f5d89e8
A
334# LB 31 Break everywhere else.
335# Match a single code point if no other rule applies.
336.;