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