Mercurial > gnulib
comparison lib/unigbrk/u-grapheme-breaks.h @ 19273:638b6d1fdf36 ueno/unicode-9.0.0
libunistring: update to Unicode 9.0.0
* lib/gen-uni-tables.c (fill_properties): Recognize Sentence_Terminal
and Prepended_Concatenation_Mark.
(is_property_default_ignorable_code_point): Exclude U+08E2.
(fill_arabicshaping): Allow missing whitespace when parsing;
recognize "AFRICAN FEH", "AFRICAN QAF", and "AFRICAN MOON".
(output_blocks): Increase the element size of the level1 table to
accommodate more blocks.
(get_lbp): Recognize ZWJ, E_Base, and E_Modifier characters;
Update each class according to the standard.
(get_wbp): Recognize ZWJ, E_Base, E_Modifier, Glue_After_Zwj, and
E_Base_GAZ characters.
(output_gbp_table): Recognize ZWJ, E_Base, E_Modifier, Glue_After_Zwj,
and E_Base_GAZ characters.
* lib/unictype.in.h (UC_JOINING_GROUP_AFRICAN_FEH,
UC_JOINING_GROUP_AFRICAN_QAF, UC_JOINING_GROUP_AFRICAN_MOON): New enum value.
* lib/unilbrk/lbrktables.h (LBP_ZWJ, LBP_EB, LBP_EM): New enum value.
* lib/unilbrk/lbrktables.c (unilbrk_table): Extend the table with
LBP_ZWJ, LBP_EB, and LBP_EM.
* lib/uniwbrk.in.h (WBP_ZWJ, WBP_EB, WBP_EM, WBP_GAZ, WBP_EBG): New
enum value.
* lib/uniwbrk/u-wordbreaks.h: Implement WB3c, WB15, and WB16.
* lib/uniwbrk/wbrktable.h (uniwbrk_prop_index): New variable declaration.
* lib/uniwbrk/wbrktable.c (uniwbrk_prop_index): New variable.
(uniwbrk_table): Implement WB14.
* tests/uniwbrk/test-uc-wordbreaks.c (wordbreakproperty_to_string):
Check WBP_ZWJ, WBP_EB, WBP_EM, WBP_GAZ, and WBP_EBG.
* modules/unigbrk/u{32,16,8}-grapheme-breaks: No longer depend on
uc-is-grapheme-break.
* modules/unigbrk/uc-grapheme-breaks: New module.
* modules/unigbrk/uc-grapheme-breaks-tests: New module.
* lib/unigbrk.in.h (GBP_ZWJ, GBP_EB, GBP_EM, GBP_GAZ, GBP_EBG): New
enum value.
(uc_grapheme_breaks): New function, replacing uc_is_grapheme_break.
* lib/unigbrk/u-grapheme-breaks.h: New file.
* lib/unigbrk/u{32,16,8}-grapheme-breaks.c: Rewrite using
u-grapheme-breaks.h instead of uc_is_grapheme_break.
* lib/unigbrk/uc-grapheme-breaks.c: New file.
* lib/unigbrk/uc-is-grapheme-break.c: Partially update to TR29 rev 29.
* tests/unigbrk/test-uc-gbrk-prop.c (graphemebreakproperty_to_string):
Check GBP_ZWJ, GBP_EB, GBP_EM, GBP_GAZ, and GBP_EBG.
* tests/unigbrk/test-uc-grapheme-breaks.c: New test.
* tests/unigbrk/test-uc-is-grapheme-break.c (graphemebreakproperty_to_string):
Check GBP_ZWJ, GBP_EB, GBP_EM, GBP_GAZ, and GBP_EBG.
(main): Skip unsupported rules involving 3 or more characters, namely
GB10, GB12, and GB13.
* lib/uniwidth/width.c (nonspacing_table_data): Update.
author | Daiki Ueno <ueno@gnu.org> |
---|---|
date | Wed, 12 Oct 2016 17:40:37 +0200 |
parents | |
children | c1cbd8206d4b |
comparison
equal
deleted
inserted
replaced
19272:c20fd8143023 | 19273:638b6d1fdf36 |
---|---|
1 /* Grapheme cluster break function. | |
2 Copyright (C) 2010-2017 Free Software Foundation, Inc. | |
3 Written by Ben Pfaff <blp@cs.stanford.edu>, 2010. | |
4 | |
5 This program is free software: you can redistribute it and/or modify it | |
6 under the terms of the GNU Lesser General Public License as published | |
7 by the Free Software Foundation; either version 3 of the License, or | |
8 (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Lesser General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Lesser General Public License | |
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | |
18 void | |
19 FUNC (const UNIT *s, size_t n, char *p) | |
20 { | |
21 if (n > 0) | |
22 { | |
23 const UNIT *s_end = s + n; | |
24 | |
25 /* Grapheme Cluster break property of the last character. | |
26 -1 at the very beginning of the string. */ | |
27 int last_char_prop = -1; | |
28 | |
29 /* Grapheme Cluster break property of the last complex character. | |
30 -1 at the very beginning of the string. */ | |
31 int last_compchar_prop = -1; | |
32 | |
33 size_t ri_count = 0; | |
34 | |
35 /* Don't break inside multibyte characters. */ | |
36 memset (p, 0, n); | |
37 | |
38 while (s < s_end) | |
39 { | |
40 ucs4_t uc; | |
41 int count = U_MBTOUC (&uc, s, s_end - s); | |
42 int prop = uc_graphemeclusterbreak_property (uc); | |
43 | |
44 /* Break at the start of the string (GB1). */ | |
45 if (last_char_prop < 0) | |
46 *p = 1; | |
47 else | |
48 { | |
49 /* No break between CR and LF (GB3). */ | |
50 if (last_char_prop == GBP_CR && prop == GBP_LF) | |
51 /* *p = 0 */; | |
52 /* Break before and after newlines (GB4, GB5). */ | |
53 else if ((last_char_prop == GBP_CR | |
54 || last_char_prop == GBP_LF | |
55 || last_char_prop == GBP_CONTROL) | |
56 || (prop == GBP_CR | |
57 || prop == GBP_LF | |
58 || prop == GBP_CONTROL)) | |
59 *p = 1; | |
60 /* No break between Hangul syllable sequences (GB6, GB7, GB8). */ | |
61 else if ((last_char_prop == GBP_L | |
62 && (prop == GBP_L | |
63 || prop == GBP_V | |
64 || prop == GBP_LV | |
65 || prop == GBP_LVT)) | |
66 || ((last_char_prop == GBP_LV | |
67 || last_char_prop == GBP_V) | |
68 && (prop == GBP_V | |
69 || prop == GBP_T)) | |
70 || ((last_char_prop == GBP_LVT | |
71 || last_char_prop == GBP_T) | |
72 && prop == GBP_T)) | |
73 /* *p = 0 */; | |
74 /* No break before extending characters or ZWJ (GB9). */ | |
75 else if (prop == GBP_EXTEND || prop == GBP_ZWJ) | |
76 /* *p = 0 */; | |
77 /* No break before SpacingMarks (GB9a). */ | |
78 else if (prop == GBP_SPACINGMARK) | |
79 /* *p = 0 */; | |
80 /* No break after Prepend characters (GB9b). */ | |
81 else if (last_char_prop == GBP_PREPEND) | |
82 /* *p = 0 */; | |
83 /* No break within emoji modifier sequences (GB10). */ | |
84 else if ((last_compchar_prop == GBP_EB | |
85 || last_compchar_prop == GBP_EBG) | |
86 && prop == GBP_EM) | |
87 /* *p = 0 */; | |
88 /* No break within emoji zwj sequences (GB11). */ | |
89 else if (last_char_prop == GBP_ZWJ | |
90 && (prop == GBP_GAZ | |
91 || prop == GBP_EBG)) | |
92 /* *p = 0 */; | |
93 /* No break between RI if there is an odd number of RI | |
94 characters before (GB12, GB13). */ | |
95 else if (prop == GBP_RI) | |
96 { | |
97 if (ri_count % 2 == 0) | |
98 *p = 1; | |
99 /* else *p = 0; */ | |
100 } | |
101 /* Break everywhere (GBP999). */ | |
102 else | |
103 *p = 1; | |
104 } | |
105 | |
106 last_char_prop = prop; | |
107 | |
108 if (!(prop == GBP_EXTEND | |
109 && (last_compchar_prop == GBP_EB | |
110 || last_compchar_prop == GBP_EBG))) | |
111 last_compchar_prop = prop; | |
112 | |
113 if (prop == GBP_RI) | |
114 ri_count++; | |
115 else | |
116 ri_count = 0; | |
117 | |
118 s += count; | |
119 p += count; | |
120 } | |
121 } | |
122 } |