xref: /aosp_15_r20/external/harfbuzz_ng/src/hb-buffer-deserialize-text-unicode.hh (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1 
2 #line 1 "hb-buffer-deserialize-text-unicode.rl"
3 /*
4  * Copyright © 2013  Google, Inc.
5  *
6  *  This is part of HarfBuzz, a text shaping library.
7  *
8  * Permission is hereby granted, without written agreement and without
9  * license or royalty fees, to use, copy, modify, and distribute this
10  * software and its documentation for any purpose, provided that the
11  * above copyright notice and the following two paragraphs appear in
12  * all copies of this software.
13  *
14  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18  * DAMAGE.
19  *
20  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
23  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25  *
26  * Google Author(s): Behdad Esfahbod
27  */
28 
29 #ifndef HB_BUFFER_DESERIALIZE_TEXT_UNICODE_HH
30 #define HB_BUFFER_DESERIALIZE_TEXT_UNICODE_HH
31 
32 #include "hb.hh"
33 
34 
35 #line 36 "hb-buffer-deserialize-text-unicode.hh"
36 static const unsigned char _deserialize_text_unicode_trans_keys[] = {
37 	0u, 0u, 9u, 117u, 43u, 102u, 48u, 102u, 48u, 57u, 9u, 124u, 9u, 124u, 9u, 124u,
38 	9u, 124u, 0
39 };
40 
41 static const char _deserialize_text_unicode_key_spans[] = {
42 	0, 109, 60, 55, 10, 116, 116, 116,
43 	116
44 };
45 
46 static const short _deserialize_text_unicode_index_offsets[] = {
47 	0, 0, 110, 171, 227, 238, 355, 472,
48 	589
49 };
50 
51 static const char _deserialize_text_unicode_indicies[] = {
52 	0, 0, 0, 0, 0, 1, 1,
53 	1, 1, 1, 1, 1, 1, 1, 1,
54 	1, 1, 1, 1, 1, 1, 1, 1,
55 	0, 1, 1, 1, 1, 1, 1, 1,
56 	1, 1, 1, 1, 1, 1, 1, 1,
57 	1, 1, 1, 1, 1, 1, 1, 1,
58 	1, 1, 1, 1, 1, 1, 1, 1,
59 	1, 1, 1, 1, 1, 1, 1, 1,
60 	1, 1, 1, 1, 1, 1, 1, 1,
61 	1, 1, 1, 1, 1, 2, 1, 1,
62 	1, 1, 1, 1, 1, 1, 1, 1,
63 	1, 1, 1, 1, 1, 1, 1, 1,
64 	1, 1, 1, 1, 1, 1, 1, 1,
65 	1, 1, 1, 1, 1, 2, 1, 3,
66 	1, 1, 1, 1, 4, 4, 4, 4,
67 	4, 4, 4, 4, 4, 4, 1, 1,
68 	1, 1, 1, 1, 1, 4, 4, 4,
69 	4, 4, 4, 1, 1, 1, 1, 1,
70 	1, 1, 1, 1, 1, 1, 1, 1,
71 	1, 1, 1, 1, 1, 1, 1, 1,
72 	1, 1, 1, 1, 1, 4, 4, 4,
73 	4, 4, 4, 1, 4, 4, 4, 4,
74 	4, 4, 4, 4, 4, 4, 1, 1,
75 	1, 1, 1, 1, 1, 4, 4, 4,
76 	4, 4, 4, 1, 1, 1, 1, 1,
77 	1, 1, 1, 1, 1, 1, 1, 1,
78 	1, 1, 1, 1, 1, 1, 1, 1,
79 	1, 1, 1, 1, 1, 4, 4, 4,
80 	4, 4, 4, 1, 5, 6, 6, 6,
81 	6, 6, 6, 6, 6, 6, 1, 7,
82 	7, 7, 7, 7, 1, 1, 1, 1,
83 	1, 1, 1, 1, 1, 1, 1, 1,
84 	1, 1, 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, 1, 1, 1, 1, 1, 1,
123 	1, 1, 1, 1, 1, 1, 1, 1,
124 	1, 1, 1, 1, 1, 1, 1, 1,
125 	1, 1, 1, 1, 13, 1, 12, 12,
126 	12, 12, 12, 1, 1, 1, 1, 1,
127 	1, 1, 1, 1, 1, 1, 1, 1,
128 	1, 1, 1, 1, 1, 12, 1, 1,
129 	1, 1, 1, 1, 1, 1, 1, 1,
130 	1, 1, 1, 1, 1, 14, 14, 14,
131 	14, 14, 14, 14, 14, 14, 14, 1,
132 	1, 1, 1, 1, 1, 1, 1, 1,
133 	1, 1, 1, 1, 1, 1, 1, 1,
134 	1, 1, 1, 1, 1, 1, 1, 1,
135 	1, 1, 1, 1, 1, 1, 1, 1,
136 	1, 1, 1, 1, 1, 1, 1, 1,
137 	1, 1, 1, 1, 1, 1, 1, 1,
138 	1, 1, 1, 1, 1, 1, 1, 1,
139 	1, 1, 1, 1, 1, 1, 1, 1,
140 	1, 13, 1, 0
141 };
142 
143 static const char _deserialize_text_unicode_trans_targs[] = {
144 	1, 0, 2, 3, 5, 7, 8, 6,
145 	5, 4, 1, 6, 6, 1, 8
146 };
147 
148 static const char _deserialize_text_unicode_trans_actions[] = {
149 	0, 0, 1, 0, 2, 2, 2, 3,
150 	0, 4, 3, 0, 5, 5, 0
151 };
152 
153 static const char _deserialize_text_unicode_eof_actions[] = {
154 	0, 0, 0, 0, 0, 3, 0, 5,
155 	5
156 };
157 
158 static const int deserialize_text_unicode_start = 1;
159 static const int deserialize_text_unicode_first_final = 5;
160 static const int deserialize_text_unicode_error = 0;
161 
162 static const int deserialize_text_unicode_en_main = 1;
163 
164 
165 #line 79 "hb-buffer-deserialize-text-unicode.rl"
166 
167 
168 static hb_bool_t
_hb_buffer_deserialize_text_unicode(hb_buffer_t * buffer,const char * buf,unsigned int buf_len,const char ** end_ptr,hb_font_t * font)169 _hb_buffer_deserialize_text_unicode (hb_buffer_t *buffer,
170 				     const char *buf,
171 				     unsigned int buf_len,
172 				     const char **end_ptr,
173 				     hb_font_t *font)
174 {
175   const char *p = buf, *pe = buf + buf_len, *eof = pe, *orig_pe = pe;
176 
177   while (p < pe && ISSPACE (*p))
178     p++;
179   if (p < pe && *p == (buffer->len ? '|' : '<'))
180     *end_ptr = ++p;
181 
182   const char *end = strchr ((char *) p, '>');
183   if (end)
184     pe = eof = end;
185   else
186   {
187     end = strrchr ((char *) p, '|');
188     if (end)
189       pe = eof = end;
190     else
191       pe = eof = p;
192   }
193 
194 
195   const char *tok = nullptr;
196   int cs;
197   hb_glyph_info_t info = {0};
198   const hb_glyph_position_t pos = {0};
199 
200 #line 201 "hb-buffer-deserialize-text-unicode.hh"
201 	{
202 	cs = deserialize_text_unicode_start;
203 	}
204 
205 #line 206 "hb-buffer-deserialize-text-unicode.hh"
206 	{
207 	int _slen;
208 	int _trans;
209 	const unsigned char *_keys;
210 	const char *_inds;
211 	if ( p == pe )
212 		goto _test_eof;
213 	if ( cs == 0 )
214 		goto _out;
215 _resume:
216 	_keys = _deserialize_text_unicode_trans_keys + (cs<<1);
217 	_inds = _deserialize_text_unicode_indicies + _deserialize_text_unicode_index_offsets[cs];
218 
219 	_slen = _deserialize_text_unicode_key_spans[cs];
220 	_trans = _inds[ _slen > 0 && _keys[0] <=(*p) &&
221 		(*p) <= _keys[1] ?
222 		(*p) - _keys[0] : _slen ];
223 
224 	cs = _deserialize_text_unicode_trans_targs[_trans];
225 
226 	if ( _deserialize_text_unicode_trans_actions[_trans] == 0 )
227 		goto _again;
228 
229 	switch ( _deserialize_text_unicode_trans_actions[_trans] ) {
230 	case 1:
231 #line 38 "hb-buffer-deserialize-text-unicode.rl"
232 	{
233 	hb_memset (&info, 0, sizeof (info));
234 }
235 	break;
236 	case 2:
237 #line 51 "hb-buffer-deserialize-text-unicode.rl"
238 	{
239 	tok = p;
240 }
241 	break;
242 	case 4:
243 #line 55 "hb-buffer-deserialize-text-unicode.rl"
244 	{if (!parse_hex (tok, p, &info.codepoint )) return false; }
245 	break;
246 	case 3:
247 #line 55 "hb-buffer-deserialize-text-unicode.rl"
248 	{if (!parse_hex (tok, p, &info.codepoint )) return false; }
249 #line 42 "hb-buffer-deserialize-text-unicode.rl"
250 	{
251 	buffer->add_info (info);
252 	if (unlikely (!buffer->successful))
253 	  return false;
254 	if (buffer->have_positions)
255 	  buffer->pos[buffer->len - 1] = pos;
256 	*end_ptr = p;
257 }
258 	break;
259 	case 5:
260 #line 57 "hb-buffer-deserialize-text-unicode.rl"
261 	{ if (!parse_uint (tok, p, &info.cluster )) return false; }
262 #line 42 "hb-buffer-deserialize-text-unicode.rl"
263 	{
264 	buffer->add_info (info);
265 	if (unlikely (!buffer->successful))
266 	  return false;
267 	if (buffer->have_positions)
268 	  buffer->pos[buffer->len - 1] = pos;
269 	*end_ptr = p;
270 }
271 	break;
272 #line 273 "hb-buffer-deserialize-text-unicode.hh"
273 	}
274 
275 _again:
276 	if ( cs == 0 )
277 		goto _out;
278 	if ( ++p != pe )
279 		goto _resume;
280 	_test_eof: {}
281 	if ( p == eof )
282 	{
283 	switch ( _deserialize_text_unicode_eof_actions[cs] ) {
284 	case 3:
285 #line 55 "hb-buffer-deserialize-text-unicode.rl"
286 	{if (!parse_hex (tok, p, &info.codepoint )) return false; }
287 #line 42 "hb-buffer-deserialize-text-unicode.rl"
288 	{
289 	buffer->add_info (info);
290 	if (unlikely (!buffer->successful))
291 	  return false;
292 	if (buffer->have_positions)
293 	  buffer->pos[buffer->len - 1] = pos;
294 	*end_ptr = p;
295 }
296 	break;
297 	case 5:
298 #line 57 "hb-buffer-deserialize-text-unicode.rl"
299 	{ if (!parse_uint (tok, p, &info.cluster )) return false; }
300 #line 42 "hb-buffer-deserialize-text-unicode.rl"
301 	{
302 	buffer->add_info (info);
303 	if (unlikely (!buffer->successful))
304 	  return false;
305 	if (buffer->have_positions)
306 	  buffer->pos[buffer->len - 1] = pos;
307 	*end_ptr = p;
308 }
309 	break;
310 #line 311 "hb-buffer-deserialize-text-unicode.hh"
311 	}
312 	}
313 
314 	_out: {}
315 	}
316 
317 #line 115 "hb-buffer-deserialize-text-unicode.rl"
318 
319 
320   if (pe < orig_pe && *pe == '>')
321   {
322     pe++;
323     if (p == pe)
324       p++;
325   }
326 
327   *end_ptr = p;
328 
329   return p == pe;
330 }
331 
332 #endif /* HB_BUFFER_DESERIALIZE_TEXT_UNICODE_HH */
333