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