string_view 0.1.0-arm64-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE-simdutf.txt +25 -0
- data/LICENSE.txt +21 -0
- data/README.md +264 -0
- data/Rakefile +20 -0
- data/ext/string_view/extconf.rb +15 -0
- data/ext/string_view/simdutf.cpp +68045 -0
- data/ext/string_view/simdutf.h +13941 -0
- data/ext/string_view/simdutf_c.h +342 -0
- data/ext/string_view/string_view.c +1217 -0
- data/lib/string_view/3.3/string_view.bundle +0 -0
- data/lib/string_view/3.4/string_view.bundle +0 -0
- data/lib/string_view/4.0/string_view.bundle +0 -0
- data/lib/string_view/version.rb +8 -0
- data/lib/string_view.rb +36 -0
- metadata +65 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/***
|
|
2
|
+
* simdutf_c.h.h - C API for simdutf
|
|
3
|
+
* This is currently experimental.
|
|
4
|
+
* We are committed to keeping the C API, but there might be mistakes in our
|
|
5
|
+
* implementation. Please report any issues you find.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef SIMDUTF_C_H
|
|
9
|
+
#define SIMDUTF_C_H
|
|
10
|
+
|
|
11
|
+
#include <stddef.h>
|
|
12
|
+
#include <stdbool.h>
|
|
13
|
+
#include <stdint.h>
|
|
14
|
+
|
|
15
|
+
#ifdef __has_include
|
|
16
|
+
#if __has_include(<uchar.h>)
|
|
17
|
+
#include <uchar.h>
|
|
18
|
+
#else // __has_include(<uchar.h>)
|
|
19
|
+
#define char16_t uint16_t
|
|
20
|
+
#define char32_t uint32_t
|
|
21
|
+
#endif // __has_include(<uchar.h>)
|
|
22
|
+
#else // __has_include(<uchar.h>)
|
|
23
|
+
#define char16_t uint16_t
|
|
24
|
+
#define char32_t uint32_t
|
|
25
|
+
#endif // __has_include
|
|
26
|
+
|
|
27
|
+
#ifdef __cplusplus
|
|
28
|
+
extern "C" {
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
/* C-friendly subset of simdutf errors */
|
|
32
|
+
typedef enum simdutf_error_code {
|
|
33
|
+
SIMDUTF_ERROR_SUCCESS = 0,
|
|
34
|
+
SIMDUTF_ERROR_HEADER_BITS,
|
|
35
|
+
SIMDUTF_ERROR_TOO_SHORT,
|
|
36
|
+
SIMDUTF_ERROR_TOO_LONG,
|
|
37
|
+
SIMDUTF_ERROR_OVERLONG,
|
|
38
|
+
SIMDUTF_ERROR_TOO_LARGE,
|
|
39
|
+
SIMDUTF_ERROR_SURROGATE,
|
|
40
|
+
SIMDUTF_ERROR_INVALID_BASE64_CHARACTER,
|
|
41
|
+
SIMDUTF_ERROR_BASE64_INPUT_REMAINDER,
|
|
42
|
+
SIMDUTF_ERROR_BASE64_EXTRA_BITS,
|
|
43
|
+
SIMDUTF_ERROR_OUTPUT_BUFFER_TOO_SMALL,
|
|
44
|
+
SIMDUTF_ERROR_OTHER
|
|
45
|
+
} simdutf_error_code;
|
|
46
|
+
|
|
47
|
+
typedef struct simdutf_result {
|
|
48
|
+
simdutf_error_code error;
|
|
49
|
+
size_t count; /* position of error or number of code units validated */
|
|
50
|
+
} simdutf_result;
|
|
51
|
+
|
|
52
|
+
typedef enum simdutf_encoding_type {
|
|
53
|
+
SIMDUTF_ENCODING_UNSPECIFIED = 0,
|
|
54
|
+
SIMDUTF_ENCODING_UTF8 = 1,
|
|
55
|
+
SIMDUTF_ENCODING_UTF16_LE = 2,
|
|
56
|
+
SIMDUTF_ENCODING_UTF16_BE = 4,
|
|
57
|
+
SIMDUTF_ENCODING_UTF32_LE = 8,
|
|
58
|
+
SIMDUTF_ENCODING_UTF32_BE = 16
|
|
59
|
+
} simdutf_encoding_type;
|
|
60
|
+
|
|
61
|
+
/* Validate UTF-8: returns true iff input is valid UTF-8 */
|
|
62
|
+
bool simdutf_validate_utf8(const char *buf, size_t len);
|
|
63
|
+
|
|
64
|
+
/* Validate UTF-8 with detailed result */
|
|
65
|
+
simdutf_result simdutf_validate_utf8_with_errors(const char *buf, size_t len);
|
|
66
|
+
|
|
67
|
+
/* Encoding detection */
|
|
68
|
+
simdutf_encoding_type simdutf_autodetect_encoding(const char *input,
|
|
69
|
+
size_t length);
|
|
70
|
+
int simdutf_detect_encodings(const char *input, size_t length);
|
|
71
|
+
|
|
72
|
+
/* ASCII validation */
|
|
73
|
+
bool simdutf_validate_ascii(const char *buf, size_t len);
|
|
74
|
+
simdutf_result simdutf_validate_ascii_with_errors(const char *buf, size_t len);
|
|
75
|
+
|
|
76
|
+
/* UTF-16 ASCII checks */
|
|
77
|
+
bool simdutf_validate_utf16_as_ascii(const char16_t *buf, size_t len);
|
|
78
|
+
bool simdutf_validate_utf16be_as_ascii(const char16_t *buf, size_t len);
|
|
79
|
+
bool simdutf_validate_utf16le_as_ascii(const char16_t *buf, size_t len);
|
|
80
|
+
|
|
81
|
+
/* UTF-16/UTF-8/UTF-32 validation (native/endian-specific) */
|
|
82
|
+
bool simdutf_validate_utf16(const char16_t *buf, size_t len);
|
|
83
|
+
bool simdutf_validate_utf16le(const char16_t *buf, size_t len);
|
|
84
|
+
bool simdutf_validate_utf16be(const char16_t *buf, size_t len);
|
|
85
|
+
simdutf_result simdutf_validate_utf16_with_errors(const char16_t *buf,
|
|
86
|
+
size_t len);
|
|
87
|
+
simdutf_result simdutf_validate_utf16le_with_errors(const char16_t *buf,
|
|
88
|
+
size_t len);
|
|
89
|
+
simdutf_result simdutf_validate_utf16be_with_errors(const char16_t *buf,
|
|
90
|
+
size_t len);
|
|
91
|
+
|
|
92
|
+
bool simdutf_validate_utf32(const char32_t *buf, size_t len);
|
|
93
|
+
simdutf_result simdutf_validate_utf32_with_errors(const char32_t *buf,
|
|
94
|
+
size_t len);
|
|
95
|
+
|
|
96
|
+
/* to_well_formed UTF-16 helpers */
|
|
97
|
+
void simdutf_to_well_formed_utf16le(const char16_t *input, size_t len,
|
|
98
|
+
char16_t *output);
|
|
99
|
+
void simdutf_to_well_formed_utf16be(const char16_t *input, size_t len,
|
|
100
|
+
char16_t *output);
|
|
101
|
+
void simdutf_to_well_formed_utf16(const char16_t *input, size_t len,
|
|
102
|
+
char16_t *output);
|
|
103
|
+
|
|
104
|
+
/* Counting */
|
|
105
|
+
size_t simdutf_count_utf16(const char16_t *input, size_t length);
|
|
106
|
+
size_t simdutf_count_utf16le(const char16_t *input, size_t length);
|
|
107
|
+
size_t simdutf_count_utf16be(const char16_t *input, size_t length);
|
|
108
|
+
size_t simdutf_count_utf8(const char *input, size_t length);
|
|
109
|
+
|
|
110
|
+
/* Length estimators */
|
|
111
|
+
size_t simdutf_utf8_length_from_latin1(const char *input, size_t length);
|
|
112
|
+
size_t simdutf_latin1_length_from_utf8(const char *input, size_t length);
|
|
113
|
+
size_t simdutf_latin1_length_from_utf16(size_t length);
|
|
114
|
+
size_t simdutf_latin1_length_from_utf32(size_t length);
|
|
115
|
+
size_t simdutf_utf16_length_from_utf8(const char *input, size_t length);
|
|
116
|
+
size_t simdutf_utf32_length_from_utf8(const char *input, size_t length);
|
|
117
|
+
size_t simdutf_utf8_length_from_utf16(const char16_t *input, size_t length);
|
|
118
|
+
size_t simdutf_utf8_length_from_utf32(const char32_t *input, size_t length);
|
|
119
|
+
simdutf_result
|
|
120
|
+
simdutf_utf8_length_from_utf16_with_replacement(const char16_t *input,
|
|
121
|
+
size_t length);
|
|
122
|
+
size_t simdutf_utf8_length_from_utf16le(const char16_t *input, size_t length);
|
|
123
|
+
size_t simdutf_utf8_length_from_utf16be(const char16_t *input, size_t length);
|
|
124
|
+
simdutf_result
|
|
125
|
+
simdutf_utf8_length_from_utf16le_with_replacement(const char16_t *input,
|
|
126
|
+
size_t length);
|
|
127
|
+
simdutf_result
|
|
128
|
+
simdutf_utf8_length_from_utf16be_with_replacement(const char16_t *input,
|
|
129
|
+
size_t length);
|
|
130
|
+
|
|
131
|
+
/* Conversions: latin1 <-> utf8, utf8 <-> utf16/utf32, utf16 <-> utf8, etc. */
|
|
132
|
+
size_t simdutf_convert_latin1_to_utf8(const char *input, size_t length,
|
|
133
|
+
char *output);
|
|
134
|
+
size_t simdutf_convert_latin1_to_utf8_safe(const char *input, size_t length,
|
|
135
|
+
char *output, size_t utf8_len);
|
|
136
|
+
size_t simdutf_convert_latin1_to_utf16le(const char *input, size_t length,
|
|
137
|
+
char16_t *output);
|
|
138
|
+
size_t simdutf_convert_latin1_to_utf16be(const char *input, size_t length,
|
|
139
|
+
char16_t *output);
|
|
140
|
+
size_t simdutf_convert_latin1_to_utf16(const char *input, size_t length,
|
|
141
|
+
char16_t *output);
|
|
142
|
+
size_t simdutf_convert_latin1_to_utf32(const char *input, size_t length,
|
|
143
|
+
char32_t *output);
|
|
144
|
+
|
|
145
|
+
size_t simdutf_convert_utf8_to_latin1(const char *input, size_t length,
|
|
146
|
+
char *output);
|
|
147
|
+
size_t simdutf_convert_utf8_to_utf16le(const char *input, size_t length,
|
|
148
|
+
char16_t *output);
|
|
149
|
+
size_t simdutf_convert_utf8_to_utf16be(const char *input, size_t length,
|
|
150
|
+
char16_t *output);
|
|
151
|
+
size_t simdutf_convert_utf8_to_utf16(const char *input, size_t length,
|
|
152
|
+
char16_t *output);
|
|
153
|
+
|
|
154
|
+
size_t simdutf_convert_utf8_to_utf32(const char *input, size_t length,
|
|
155
|
+
char32_t *output);
|
|
156
|
+
simdutf_result simdutf_convert_utf8_to_latin1_with_errors(const char *input,
|
|
157
|
+
size_t length,
|
|
158
|
+
char *output);
|
|
159
|
+
simdutf_result simdutf_convert_utf8_to_utf16_with_errors(const char *input,
|
|
160
|
+
size_t length,
|
|
161
|
+
char16_t *output);
|
|
162
|
+
simdutf_result simdutf_convert_utf8_to_utf16le_with_errors(const char *input,
|
|
163
|
+
size_t length,
|
|
164
|
+
char16_t *output);
|
|
165
|
+
simdutf_result simdutf_convert_utf8_to_utf16be_with_errors(const char *input,
|
|
166
|
+
size_t length,
|
|
167
|
+
char16_t *output);
|
|
168
|
+
simdutf_result simdutf_convert_utf8_to_utf32_with_errors(const char *input,
|
|
169
|
+
size_t length,
|
|
170
|
+
char32_t *output);
|
|
171
|
+
|
|
172
|
+
/* Conversions assuming valid input */
|
|
173
|
+
size_t simdutf_convert_valid_utf8_to_latin1(const char *input, size_t length,
|
|
174
|
+
char *output);
|
|
175
|
+
size_t simdutf_convert_valid_utf8_to_utf16le(const char *input, size_t length,
|
|
176
|
+
char16_t *output);
|
|
177
|
+
size_t simdutf_convert_valid_utf8_to_utf16be(const char *input, size_t length,
|
|
178
|
+
char16_t *output);
|
|
179
|
+
size_t simdutf_convert_valid_utf8_to_utf32(const char *input, size_t length,
|
|
180
|
+
char32_t *output);
|
|
181
|
+
|
|
182
|
+
/* UTF-16 -> UTF-8 and related conversions */
|
|
183
|
+
size_t simdutf_convert_utf16_to_utf8(const char16_t *input, size_t length,
|
|
184
|
+
char *output);
|
|
185
|
+
size_t simdutf_convert_utf16le_to_utf8(const char16_t *input, size_t length,
|
|
186
|
+
char *output);
|
|
187
|
+
size_t simdutf_convert_utf16be_to_utf8(const char16_t *input, size_t length,
|
|
188
|
+
char *output);
|
|
189
|
+
size_t simdutf_convert_utf16_to_utf8_safe(const char16_t *input, size_t length,
|
|
190
|
+
char *output, size_t utf8_len);
|
|
191
|
+
size_t simdutf_convert_utf16_to_latin1(const char16_t *input, size_t length,
|
|
192
|
+
char *output);
|
|
193
|
+
size_t simdutf_convert_utf16le_to_latin1(const char16_t *input, size_t length,
|
|
194
|
+
char *output);
|
|
195
|
+
size_t simdutf_convert_utf16be_to_latin1(const char16_t *input, size_t length,
|
|
196
|
+
char *output);
|
|
197
|
+
simdutf_result
|
|
198
|
+
simdutf_convert_utf16_to_latin1_with_errors(const char16_t *input,
|
|
199
|
+
size_t length, char *output);
|
|
200
|
+
simdutf_result
|
|
201
|
+
simdutf_convert_utf16le_to_latin1_with_errors(const char16_t *input,
|
|
202
|
+
size_t length, char *output);
|
|
203
|
+
simdutf_result
|
|
204
|
+
simdutf_convert_utf16be_to_latin1_with_errors(const char16_t *input,
|
|
205
|
+
size_t length, char *output);
|
|
206
|
+
|
|
207
|
+
simdutf_result simdutf_convert_utf16_to_utf8_with_errors(const char16_t *input,
|
|
208
|
+
size_t length,
|
|
209
|
+
char *output);
|
|
210
|
+
simdutf_result
|
|
211
|
+
simdutf_convert_utf16le_to_utf8_with_errors(const char16_t *input,
|
|
212
|
+
size_t length, char *output);
|
|
213
|
+
simdutf_result
|
|
214
|
+
simdutf_convert_utf16be_to_utf8_with_errors(const char16_t *input,
|
|
215
|
+
size_t length, char *output);
|
|
216
|
+
|
|
217
|
+
size_t simdutf_convert_valid_utf16_to_utf8(const char16_t *input, size_t length,
|
|
218
|
+
char *output);
|
|
219
|
+
size_t simdutf_convert_valid_utf16_to_latin1(const char16_t *input,
|
|
220
|
+
size_t length, char *output);
|
|
221
|
+
size_t simdutf_convert_valid_utf16le_to_latin1(const char16_t *input,
|
|
222
|
+
size_t length, char *output);
|
|
223
|
+
size_t simdutf_convert_valid_utf16be_to_latin1(const char16_t *input,
|
|
224
|
+
size_t length, char *output);
|
|
225
|
+
|
|
226
|
+
size_t simdutf_convert_valid_utf16le_to_utf8(const char16_t *input,
|
|
227
|
+
size_t length, char *output);
|
|
228
|
+
size_t simdutf_convert_valid_utf16be_to_utf8(const char16_t *input,
|
|
229
|
+
size_t length, char *output);
|
|
230
|
+
|
|
231
|
+
/* UTF-16 <-> UTF-32 conversions */
|
|
232
|
+
size_t simdutf_convert_utf16_to_utf32(const char16_t *input, size_t length,
|
|
233
|
+
char32_t *output);
|
|
234
|
+
size_t simdutf_convert_utf16le_to_utf32(const char16_t *input, size_t length,
|
|
235
|
+
char32_t *output);
|
|
236
|
+
size_t simdutf_convert_utf16be_to_utf32(const char16_t *input, size_t length,
|
|
237
|
+
char32_t *output);
|
|
238
|
+
simdutf_result simdutf_convert_utf16_to_utf32_with_errors(const char16_t *input,
|
|
239
|
+
size_t length,
|
|
240
|
+
char32_t *output);
|
|
241
|
+
simdutf_result
|
|
242
|
+
simdutf_convert_utf16le_to_utf32_with_errors(const char16_t *input,
|
|
243
|
+
size_t length, char32_t *output);
|
|
244
|
+
simdutf_result
|
|
245
|
+
simdutf_convert_utf16be_to_utf32_with_errors(const char16_t *input,
|
|
246
|
+
size_t length, char32_t *output);
|
|
247
|
+
|
|
248
|
+
/* Valid UTF-16 conversions */
|
|
249
|
+
size_t simdutf_convert_valid_utf16_to_utf32(const char16_t *input,
|
|
250
|
+
size_t length, char32_t *output);
|
|
251
|
+
size_t simdutf_convert_valid_utf16le_to_utf32(const char16_t *input,
|
|
252
|
+
size_t length, char32_t *output);
|
|
253
|
+
size_t simdutf_convert_valid_utf16be_to_utf32(const char16_t *input,
|
|
254
|
+
size_t length, char32_t *output);
|
|
255
|
+
|
|
256
|
+
/* UTF-32 -> ... conversions */
|
|
257
|
+
size_t simdutf_convert_utf32_to_utf8(const char32_t *input, size_t length,
|
|
258
|
+
char *output);
|
|
259
|
+
simdutf_result simdutf_convert_utf32_to_utf8_with_errors(const char32_t *input,
|
|
260
|
+
size_t length,
|
|
261
|
+
char *output);
|
|
262
|
+
size_t simdutf_convert_valid_utf32_to_utf8(const char32_t *input, size_t length,
|
|
263
|
+
char *output);
|
|
264
|
+
|
|
265
|
+
size_t simdutf_convert_utf32_to_utf16(const char32_t *input, size_t length,
|
|
266
|
+
char16_t *output);
|
|
267
|
+
size_t simdutf_convert_utf32_to_utf16le(const char32_t *input, size_t length,
|
|
268
|
+
char16_t *output);
|
|
269
|
+
size_t simdutf_convert_utf32_to_utf16be(const char32_t *input, size_t length,
|
|
270
|
+
char16_t *output);
|
|
271
|
+
simdutf_result
|
|
272
|
+
simdutf_convert_utf32_to_latin1_with_errors(const char32_t *input,
|
|
273
|
+
size_t length, char *output);
|
|
274
|
+
|
|
275
|
+
/* --- Find helpers --- */
|
|
276
|
+
const char *simdutf_find(const char *start, const char *end, char character);
|
|
277
|
+
const char16_t *simdutf_find_utf16(const char16_t *start, const char16_t *end,
|
|
278
|
+
char16_t character);
|
|
279
|
+
|
|
280
|
+
/* --- Base64 enums and helpers --- */
|
|
281
|
+
typedef enum simdutf_base64_options {
|
|
282
|
+
SIMDUTF_BASE64_DEFAULT = 0,
|
|
283
|
+
SIMDUTF_BASE64_URL = 1,
|
|
284
|
+
SIMDUTF_BASE64_DEFAULT_NO_PADDING = 2,
|
|
285
|
+
SIMDUTF_BASE64_URL_WITH_PADDING = 3,
|
|
286
|
+
SIMDUTF_BASE64_DEFAULT_ACCEPT_GARBAGE = 4,
|
|
287
|
+
SIMDUTF_BASE64_URL_ACCEPT_GARBAGE = 5,
|
|
288
|
+
SIMDUTF_BASE64_DEFAULT_OR_URL = 8,
|
|
289
|
+
SIMDUTF_BASE64_DEFAULT_OR_URL_ACCEPT_GARBAGE = 12
|
|
290
|
+
} simdutf_base64_options;
|
|
291
|
+
|
|
292
|
+
typedef enum simdutf_last_chunk_handling_options {
|
|
293
|
+
SIMDUTF_LAST_CHUNK_LOOSE = 0,
|
|
294
|
+
SIMDUTF_LAST_CHUNK_STRICT = 1,
|
|
295
|
+
SIMDUTF_LAST_CHUNK_STOP_BEFORE_PARTIAL = 2,
|
|
296
|
+
SIMDUTF_LAST_CHUNK_ONLY_FULL_CHUNKS = 3
|
|
297
|
+
} simdutf_last_chunk_handling_options;
|
|
298
|
+
|
|
299
|
+
/* maximal binary length estimators */
|
|
300
|
+
size_t simdutf_maximal_binary_length_from_base64(const char *input,
|
|
301
|
+
size_t length);
|
|
302
|
+
size_t simdutf_maximal_binary_length_from_base64_utf16(const char16_t *input,
|
|
303
|
+
size_t length);
|
|
304
|
+
|
|
305
|
+
/* base64 decoding/encoding */
|
|
306
|
+
simdutf_result simdutf_base64_to_binary(
|
|
307
|
+
const char *input, size_t length, char *output,
|
|
308
|
+
simdutf_base64_options options,
|
|
309
|
+
simdutf_last_chunk_handling_options last_chunk_options);
|
|
310
|
+
simdutf_result simdutf_base64_to_binary_utf16(
|
|
311
|
+
const char16_t *input, size_t length, char *output,
|
|
312
|
+
simdutf_base64_options options,
|
|
313
|
+
simdutf_last_chunk_handling_options last_chunk_options);
|
|
314
|
+
|
|
315
|
+
size_t simdutf_base64_length_from_binary(size_t length,
|
|
316
|
+
simdutf_base64_options options);
|
|
317
|
+
size_t simdutf_base64_length_from_binary_with_lines(
|
|
318
|
+
size_t length, simdutf_base64_options options, size_t line_length);
|
|
319
|
+
|
|
320
|
+
size_t simdutf_binary_to_base64(const char *input, size_t length, char *output,
|
|
321
|
+
simdutf_base64_options options);
|
|
322
|
+
size_t simdutf_binary_to_base64_with_lines(const char *input, size_t length,
|
|
323
|
+
char *output, size_t line_length,
|
|
324
|
+
simdutf_base64_options options);
|
|
325
|
+
|
|
326
|
+
/* safe decoding that provides an in/out outlen parameter */
|
|
327
|
+
simdutf_result simdutf_base64_to_binary_safe(
|
|
328
|
+
const char *input, size_t length, char *output, size_t *outlen,
|
|
329
|
+
simdutf_base64_options options,
|
|
330
|
+
simdutf_last_chunk_handling_options last_chunk_options,
|
|
331
|
+
bool decode_up_to_bad_char);
|
|
332
|
+
simdutf_result simdutf_base64_to_binary_safe_utf16(
|
|
333
|
+
const char16_t *input, size_t length, char *output, size_t *outlen,
|
|
334
|
+
simdutf_base64_options options,
|
|
335
|
+
simdutf_last_chunk_handling_options last_chunk_options,
|
|
336
|
+
bool decode_up_to_bad_char);
|
|
337
|
+
|
|
338
|
+
#ifdef __cplusplus
|
|
339
|
+
} /* extern "C" */
|
|
340
|
+
#endif
|
|
341
|
+
|
|
342
|
+
#endif /* SIMDUTF_C_H */
|