This source file includes following definitions.
- u16_possible_linebreaks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #include <config.h>
27
28
29 #include "unilbrk.h"
30
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include "unilbrk/lbrktables.h"
35 #include "uniwidth/cjk.h"
36 #include "unistr.h"
37
38 void
39 u16_possible_linebreaks (const uint16_t *s, size_t n, const char *encoding, char *p)
40 {
41 if (n > 0)
42 {
43 int LBP_AI_REPLACEMENT = (is_cjk_encoding (encoding) ? LBP_ID : LBP_AL);
44 const uint16_t *s_end = s + n;
45 int last_prop = LBP_BK;
46 char *seen_space = NULL;
47 char *seen_space2 = NULL;
48
49
50 memset (p, UC_BREAK_PROHIBITED, n);
51
52 do
53 {
54 ucs4_t uc;
55 int count = u16_mbtouc_unsafe (&uc, s, s_end - s);
56 int prop = unilbrkprop_lookup (uc);
57
58 if (prop == LBP_BK)
59 {
60
61 *p = UC_BREAK_MANDATORY;
62 last_prop = LBP_BK;
63 seen_space = NULL;
64 seen_space2 = NULL;
65 }
66 else
67 {
68 char *q;
69
70
71 switch (prop)
72 {
73 case LBP_AI:
74
75 prop = LBP_AI_REPLACEMENT;
76 break;
77 case LBP_CB:
78
79 prop = LBP_ID;
80 break;
81 case LBP_SA:
82
83
84 case LBP_XX:
85
86 prop = LBP_AL;
87 break;
88 }
89
90
91 q = p;
92 if (prop == LBP_SP)
93 {
94
95 *p = UC_BREAK_PROHIBITED;
96 seen_space2 = seen_space;
97 seen_space = p;
98 }
99 else if (prop == LBP_ZW)
100 {
101
102 *p = UC_BREAK_PROHIBITED;
103 last_prop = LBP_ZW;
104 seen_space = NULL;
105 seen_space2 = NULL;
106 }
107 else if (prop == LBP_CM)
108 {
109
110
111 if (last_prop == LBP_ZW)
112 {
113
114 *p = UC_BREAK_POSSIBLE;
115
116 last_prop = LBP_ID;
117 }
118 else
119 {
120 *p = UC_BREAK_PROHIBITED;
121
122 if (seen_space != NULL)
123 {
124 q = seen_space;
125 seen_space = seen_space2;
126 prop = LBP_ID;
127 goto lookup_via_table;
128 }
129 }
130 }
131 else
132 {
133 lookup_via_table:
134
135 if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0])))
136 abort ();
137
138 if (last_prop == LBP_BK)
139 {
140
141 *q = UC_BREAK_PROHIBITED;
142 }
143 else if (last_prop == LBP_ZW)
144 {
145
146 *q = UC_BREAK_POSSIBLE;
147 }
148 else
149 {
150 switch (unilbrk_table [last_prop] [prop])
151 {
152 case D:
153 *q = UC_BREAK_POSSIBLE;
154 break;
155 case I:
156 *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED);
157 break;
158 case P:
159 *q = UC_BREAK_PROHIBITED;
160 break;
161 default:
162 abort ();
163 }
164 }
165 last_prop = prop;
166 seen_space = NULL;
167 seen_space2 = NULL;
168 }
169 }
170
171 s += count;
172 p += count;
173 }
174 while (s < s_end);
175 }
176 }