forked from google/emoji-segmenter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emoji_presentation_scanner.c
249 lines (212 loc) · 5.58 KB
/
emoji_presentation_scanner.c
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#line 1 "emoji_presentation_scanner.rl"
/* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdbool.h>
#ifndef EMOJI_LINKAGE
#define EMOJI_LINKAGE static
#endif
#line 23 "emoji_presentation_scanner.c"
static const unsigned char _emoji_presentation_trans_keys[] = {
0u, 13u, 14u, 15u, 0u, 13u, 9u, 12u, 10u, 12u, 10u, 10u, 4u, 12u, 4u, 12u,
6u, 6u, 9u, 12u, 8u, 8u, 8u, 10u, 9u, 14u, 0
};
static const char _emoji_presentation_key_spans[] = {
14, 2, 14, 4, 3, 1, 9, 9,
1, 4, 1, 3, 6
};
static const char _emoji_presentation_index_offsets[] = {
0, 15, 18, 33, 38, 42, 44, 54,
64, 66, 71, 73, 77
};
static const char _emoji_presentation_indicies[] = {
1, 1, 1, 2, 0, 0, 0, 1,
0, 0, 0, 0, 0, 1, 0, 4,
5, 3, 6, 6, 7, 8, 9, 9,
10, 11, 9, 9, 9, 9, 9, 12,
9, 5, 13, 14, 15, 0, 13, 16,
17, 16, 13, 0, 17, 16, 16, 16,
16, 16, 13, 16, 17, 16, 17, 16,
16, 16, 16, 5, 13, 14, 15, 16,
5, 18, 5, 13, 19, 20, 18, 14,
21, 23, 22, 13, 22, 5, 13, 14,
15, 16, 4, 16, 0
};
static const char _emoji_presentation_trans_targs[] = {
2, 4, 6, 2, 1, 2, 3, 3,
7, 2, 8, 9, 12, 0, 2, 5,
2, 5, 2, 10, 11, 2, 2, 2
};
static const char _emoji_presentation_trans_actions[] = {
1, 2, 2, 3, 0, 4, 7, 2,
2, 8, 0, 7, 2, 0, 9, 10,
11, 2, 12, 0, 10, 13, 14, 15
};
static const char _emoji_presentation_to_state_actions[] = {
0, 0, 5, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
};
static const char _emoji_presentation_from_state_actions[] = {
0, 0, 6, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
};
static const char _emoji_presentation_eof_trans[] = {
1, 4, 0, 1, 17, 1, 17, 17,
19, 19, 22, 23, 17
};
static const int emoji_presentation_start = 2;
static const int emoji_presentation_en_text_and_emoji_run = 2;
#line 26 "emoji_presentation_scanner.rl"
#line 100 "emoji_presentation_scanner.rl"
EMOJI_LINKAGE emoji_text_iter_t
scan_emoji_presentation (emoji_text_iter_t p,
const emoji_text_iter_t pe,
bool* is_emoji,
bool* has_vs)
{
emoji_text_iter_t ts;
emoji_text_iter_t te;
const emoji_text_iter_t eof = pe;
unsigned act;
int cs;
#line 100 "emoji_presentation_scanner.c"
{
cs = emoji_presentation_start;
ts = 0;
te = 0;
act = 0;
}
#line 106 "emoji_presentation_scanner.c"
{
int _slen;
int _trans;
const unsigned char *_keys;
const char *_inds;
if ( p == pe )
goto _test_eof;
_resume:
switch ( _emoji_presentation_from_state_actions[cs] ) {
case 6:
#line 1 "NONE"
{ts = p;}
break;
#line 118 "emoji_presentation_scanner.c"
}
_keys = _emoji_presentation_trans_keys + (cs<<1);
_inds = _emoji_presentation_indicies + _emoji_presentation_index_offsets[cs];
_slen = _emoji_presentation_key_spans[cs];
_trans = _inds[ _slen > 0 && _keys[0] <=(*p) &&
(*p) <= _keys[1] ?
(*p) - _keys[0] : _slen ];
_eof_trans:
cs = _emoji_presentation_trans_targs[_trans];
if ( _emoji_presentation_trans_actions[_trans] == 0 )
goto _again;
switch ( _emoji_presentation_trans_actions[_trans] ) {
case 9:
#line 94 "emoji_presentation_scanner.rl"
{te = p+1;{ *is_emoji = false; *has_vs = true; return te; }}
break;
case 15:
#line 95 "emoji_presentation_scanner.rl"
{te = p+1;{ *is_emoji = true; *has_vs = true; return te; }}
break;
case 4:
#line 96 "emoji_presentation_scanner.rl"
{te = p+1;{ *is_emoji = true; *has_vs = false; return te; }}
break;
case 8:
#line 97 "emoji_presentation_scanner.rl"
{te = p+1;{ *is_emoji = false; *has_vs = false; return te; }}
break;
case 13:
#line 94 "emoji_presentation_scanner.rl"
{te = p;p--;{ *is_emoji = false; *has_vs = true; return te; }}
break;
case 14:
#line 95 "emoji_presentation_scanner.rl"
{te = p;p--;{ *is_emoji = true; *has_vs = true; return te; }}
break;
case 11:
#line 96 "emoji_presentation_scanner.rl"
{te = p;p--;{ *is_emoji = true; *has_vs = false; return te; }}
break;
case 12:
#line 97 "emoji_presentation_scanner.rl"
{te = p;p--;{ *is_emoji = false; *has_vs = false; return te; }}
break;
case 3:
#line 96 "emoji_presentation_scanner.rl"
{{p = ((te))-1;}{ *is_emoji = true; *has_vs = false; return te; }}
break;
case 1:
#line 1 "NONE"
{ switch( act ) {
case 2:
{{p = ((te))-1;} *is_emoji = true; *has_vs = true; return te; }
break;
case 3:
{{p = ((te))-1;} *is_emoji = true; *has_vs = false; return te; }
break;
case 4:
{{p = ((te))-1;} *is_emoji = false; *has_vs = false; return te; }
break;
}
}
break;
case 10:
#line 1 "NONE"
{te = p+1;}
#line 95 "emoji_presentation_scanner.rl"
{act = 2;}
break;
case 2:
#line 1 "NONE"
{te = p+1;}
#line 96 "emoji_presentation_scanner.rl"
{act = 3;}
break;
case 7:
#line 1 "NONE"
{te = p+1;}
#line 97 "emoji_presentation_scanner.rl"
{act = 4;}
break;
#line 188 "emoji_presentation_scanner.c"
}
_again:
switch ( _emoji_presentation_to_state_actions[cs] ) {
case 5:
#line 1 "NONE"
{ts = 0;}
break;
#line 195 "emoji_presentation_scanner.c"
}
if ( ++p != pe )
goto _resume;
_test_eof: {}
if ( p == eof )
{
if ( _emoji_presentation_eof_trans[cs] > 0 ) {
_trans = _emoji_presentation_eof_trans[cs] - 1;
goto _eof_trans;
}
}
}
#line 118 "emoji_presentation_scanner.rl"
/* Should not be reached. */
*is_emoji = false;
*has_vs = false;
return p;
}