bare-url 1.1.1 → 1.2.0
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.
- package/binding.c +31 -17
- package/index.js +31 -10
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/bare-url.bare +0 -0
- package/prebuilds/darwin-x64/bare-url.bare +0 -0
- package/prebuilds/linux-arm64/bare-url.bare +0 -0
- package/prebuilds/linux-x64/bare-url.bare +0 -0
- package/prebuilds/win32-x64/bare-url.bare +0 -0
- package/vendor/liburl/src/parse.h +4 -2
- package/vendor/libutf/CMakeLists.txt +23 -6
- package/vendor/libutf/include/utf/string.h +44 -18
- package/vendor/libutf/include/utf.h +87 -0
- package/vendor/libutf/src/ascii/validate.c +47 -0
- package/vendor/libutf/src/endianness.c +1 -1
- package/vendor/libutf/src/latin1/convert-to-utf16.c +37 -0
- package/vendor/libutf/src/latin1/convert-to-utf32.c +34 -0
- package/vendor/libutf/src/latin1/convert-to-utf8.c +58 -0
- package/vendor/libutf/src/latin1/length-from-utf16.c +26 -0
- package/vendor/libutf/src/latin1/length-from-utf32.c +26 -0
- package/vendor/libutf/src/latin1/length-from-utf8.c +34 -0
- package/vendor/libutf/src/utf16/convert-to-latin1.c +41 -0
- package/vendor/libutf/src/utf16/convert-to-utf32.c +56 -0
- package/vendor/libutf/src/utf16/{utf8-convert.c → convert-to-utf8.c} +1 -3
- package/vendor/libutf/src/utf16/length-from-latin1.c +26 -0
- package/vendor/libutf/src/utf16/length-from-utf32.c +33 -0
- package/vendor/libutf/src/{utf8/utf16-length.c → utf16/length-from-utf8.c} +0 -1
- package/vendor/libutf/src/utf16/validate.c +1 -1
- package/vendor/libutf/src/utf32/convert-to-latin1.c +40 -0
- package/vendor/libutf/src/utf32/convert-to-utf16.c +56 -0
- package/vendor/libutf/src/utf32/convert-to-utf8.c +71 -0
- package/vendor/libutf/src/utf32/length-from-latin1.c +26 -0
- package/vendor/libutf/src/utf32/length-from-utf16.c +35 -0
- package/vendor/libutf/src/utf32/length-from-utf8.c +35 -0
- package/vendor/libutf/src/utf32/validate.c +39 -0
- package/vendor/libutf/src/utf8/convert-to-latin1.c +70 -0
- package/vendor/libutf/src/utf8/{utf16-convert.c → convert-to-utf16.c} +10 -5
- package/vendor/libutf/src/utf8/convert-to-utf32.c +110 -0
- package/vendor/libutf/src/utf8/length-from-latin1.c +32 -0
- package/vendor/libutf/src/{utf16/utf8-length.c → utf8/length-from-utf16.c} +1 -2
- package/vendor/libutf/src/utf8/length-from-utf32.c +35 -0
- package/vendor/libutf/src/utf8/string.c +2 -1
- package/vendor/libutf/src/utf8/validate.c +9 -9
- /package/vendor/libutf/{include/utf → src}/endianness.h +0 -0
package/binding.c
CHANGED
|
@@ -14,13 +14,17 @@ static js_value_t *
|
|
|
14
14
|
bare_url_parse (js_env_t *env, js_callback_info_t *info) {
|
|
15
15
|
int err;
|
|
16
16
|
|
|
17
|
-
size_t argc =
|
|
18
|
-
js_value_t *argv[
|
|
17
|
+
size_t argc = 4;
|
|
18
|
+
js_value_t *argv[4];
|
|
19
19
|
|
|
20
20
|
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
21
21
|
assert(err == 0);
|
|
22
22
|
|
|
23
|
-
assert(argc ==
|
|
23
|
+
assert(argc == 4);
|
|
24
|
+
|
|
25
|
+
bool should_throw;
|
|
26
|
+
err = js_get_value_bool(env, argv[3], &should_throw);
|
|
27
|
+
assert(err == 0);
|
|
24
28
|
|
|
25
29
|
bool has_base;
|
|
26
30
|
err = js_is_string(env, argv[1], &has_base);
|
|
@@ -45,7 +49,7 @@ bare_url_parse (js_env_t *env, js_callback_info_t *info) {
|
|
|
45
49
|
if (err < 0) {
|
|
46
50
|
url_destroy(&base);
|
|
47
51
|
|
|
48
|
-
js_throw_error(env, NULL, "Invalid base URL");
|
|
52
|
+
if (should_throw) js_throw_error(env, NULL, "Invalid base URL");
|
|
49
53
|
|
|
50
54
|
return NULL;
|
|
51
55
|
}
|
|
@@ -72,7 +76,7 @@ bare_url_parse (js_env_t *env, js_callback_info_t *info) {
|
|
|
72
76
|
url_destroy(&base);
|
|
73
77
|
url_destroy(&url);
|
|
74
78
|
|
|
75
|
-
js_throw_error(env, NULL, "Invalid URL");
|
|
79
|
+
if (should_throw) js_throw_error(env, NULL, "Invalid URL");
|
|
76
80
|
|
|
77
81
|
return NULL;
|
|
78
82
|
}
|
|
@@ -81,17 +85,8 @@ bare_url_parse (js_env_t *env, js_callback_info_t *info) {
|
|
|
81
85
|
err = js_create_string_utf8(env, url.href.data, url.href.len, &href);
|
|
82
86
|
assert(err == 0);
|
|
83
87
|
|
|
84
|
-
bool tag;
|
|
85
|
-
err = js_get_value_bool(env, argv[2], &tag);
|
|
86
|
-
assert(err == 0);
|
|
87
|
-
|
|
88
|
-
if (tag) {
|
|
89
|
-
err = js_add_type_tag(env, argv[3], &bare_url__tag);
|
|
90
|
-
assert(err == 0);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
88
|
uint32_t *components;
|
|
94
|
-
err = js_get_typedarray_info(env, argv[
|
|
89
|
+
err = js_get_typedarray_info(env, argv[2], NULL, (void **) &components, NULL, NULL, NULL);
|
|
95
90
|
assert(err == 0);
|
|
96
91
|
|
|
97
92
|
memcpy(components, &url.components, sizeof(url.components));
|
|
@@ -171,7 +166,25 @@ bare_url_can_parse (js_env_t *env, js_callback_info_t *info) {
|
|
|
171
166
|
}
|
|
172
167
|
|
|
173
168
|
static js_value_t *
|
|
174
|
-
|
|
169
|
+
bare_url_tag (js_env_t *env, js_callback_info_t *info) {
|
|
170
|
+
int err;
|
|
171
|
+
|
|
172
|
+
size_t argc = 1;
|
|
173
|
+
js_value_t *argv[1];
|
|
174
|
+
|
|
175
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
176
|
+
assert(err == 0);
|
|
177
|
+
|
|
178
|
+
assert(argc == 1);
|
|
179
|
+
|
|
180
|
+
err = js_add_type_tag(env, argv[0], &bare_url__tag);
|
|
181
|
+
assert(err == 0);
|
|
182
|
+
|
|
183
|
+
return NULL;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static js_value_t *
|
|
187
|
+
bare_url_is_tagged (js_env_t *env, js_callback_info_t *info) {
|
|
175
188
|
int err;
|
|
176
189
|
|
|
177
190
|
size_t argc = 1;
|
|
@@ -208,7 +221,8 @@ bare_url_exports (js_env_t *env, js_value_t *exports) {
|
|
|
208
221
|
|
|
209
222
|
V("parse", bare_url_parse)
|
|
210
223
|
V("canParse", bare_url_can_parse)
|
|
211
|
-
V("
|
|
224
|
+
V("tag", bare_url_tag)
|
|
225
|
+
V("isTagged", bare_url_is_tagged)
|
|
212
226
|
#undef V
|
|
213
227
|
|
|
214
228
|
return exports;
|
package/index.js
CHANGED
|
@@ -7,14 +7,20 @@ const errors = require('./lib/errors')
|
|
|
7
7
|
const isWindows = Bare.platform === 'win32'
|
|
8
8
|
|
|
9
9
|
const URL = module.exports = exports = class URL {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
static {
|
|
11
|
+
binding.tag(this)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
constructor (input, base, opts = {}) {
|
|
15
|
+
if (arguments.length === 0) throw errors.INVALID_URL()
|
|
16
|
+
|
|
17
|
+
input = `${input}`
|
|
12
18
|
|
|
13
|
-
if (base
|
|
19
|
+
if (base !== undefined) base = `${base}`
|
|
14
20
|
|
|
15
21
|
this._components = new Uint32Array(8)
|
|
16
22
|
|
|
17
|
-
this._parse(
|
|
23
|
+
this._parse(input, base, opts.throw !== false)
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
// https://url.spec.whatwg.org/#dom-url-href
|
|
@@ -204,9 +210,9 @@ const URL = module.exports = exports = class URL {
|
|
|
204
210
|
return this._slice(0, start) + replacement + this._slice(end)
|
|
205
211
|
}
|
|
206
212
|
|
|
207
|
-
_parse (href, base,
|
|
213
|
+
_parse (href, base, shouldThrow) {
|
|
208
214
|
try {
|
|
209
|
-
this._href = binding.parse(String(href), base ? String(base) : null,
|
|
215
|
+
this._href = binding.parse(String(href), base ? String(base) : null, this._components, shouldThrow)
|
|
210
216
|
} catch (err) {
|
|
211
217
|
safetyCatch(err)
|
|
212
218
|
|
|
@@ -216,7 +222,7 @@ const URL = module.exports = exports = class URL {
|
|
|
216
222
|
|
|
217
223
|
_update (href) {
|
|
218
224
|
try {
|
|
219
|
-
this._parse(href, null,
|
|
225
|
+
this._parse(href, null, true)
|
|
220
226
|
} catch (err) {
|
|
221
227
|
safetyCatch(err)
|
|
222
228
|
}
|
|
@@ -236,11 +242,26 @@ function cannotHaveCredentialsOrPort (url) {
|
|
|
236
242
|
exports.URL = exports // For Node.js compatibility
|
|
237
243
|
|
|
238
244
|
exports.isURL = function isURL (value) {
|
|
239
|
-
|
|
245
|
+
if (typeof value !== 'object' || value === null) return false
|
|
246
|
+
|
|
247
|
+
let constructor = value.constructor
|
|
248
|
+
|
|
249
|
+
while (typeof constructor === 'function') {
|
|
250
|
+
if (binding.isTagged(constructor)) return true
|
|
251
|
+
|
|
252
|
+
constructor = Reflect.getPrototypeOf(constructor)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return false
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
exports.parse = function parse (input, base) {
|
|
259
|
+
const url = new URL(input, base, { throw: false })
|
|
260
|
+
return url.href ? url : null
|
|
240
261
|
}
|
|
241
262
|
|
|
242
|
-
exports.canParse = function canParse (
|
|
243
|
-
return binding.canParse(String(
|
|
263
|
+
exports.canParse = function canParse (input, base) {
|
|
264
|
+
return binding.canParse(String(input), base ? String(base) : null)
|
|
244
265
|
}
|
|
245
266
|
|
|
246
267
|
exports.fileURLToPath = function fileURLToPath (url) {
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -882,8 +882,10 @@ url__parse (url_t *url, const utf8_string_view_t input, const url_t *base) {
|
|
|
882
882
|
utf8_string_view_t host = url_get_host(base);
|
|
883
883
|
|
|
884
884
|
if (!utf8_string_view_empty(host)) {
|
|
885
|
-
|
|
886
|
-
|
|
885
|
+
if (url->type == url_type_opaque) {
|
|
886
|
+
err = utf8_string_append_literal(&url->href, (utf8_t *) "//", 2);
|
|
887
|
+
if (err < 0) goto err;
|
|
888
|
+
}
|
|
887
889
|
|
|
888
890
|
utf8_string_view_t username = url_get_username(base);
|
|
889
891
|
|
|
@@ -15,17 +15,33 @@ target_sources(
|
|
|
15
15
|
utf
|
|
16
16
|
INTERFACE
|
|
17
17
|
include/utf.h
|
|
18
|
-
include/utf/endianness.h
|
|
19
18
|
include/utf/string.h
|
|
20
19
|
PRIVATE
|
|
21
20
|
src/endianness.c
|
|
22
|
-
src/
|
|
23
|
-
src/
|
|
24
|
-
src/utf8/
|
|
21
|
+
src/endianness.h
|
|
22
|
+
src/ascii/validate.c
|
|
23
|
+
src/utf8/convert-to-latin1.c
|
|
24
|
+
src/utf8/convert-to-utf16.c
|
|
25
|
+
src/utf8/convert-to-utf32.c
|
|
26
|
+
src/utf8/length-from-latin1.c
|
|
27
|
+
src/utf8/length-from-utf16.c
|
|
28
|
+
src/utf8/length-from-utf32.c
|
|
25
29
|
src/utf8/string.c
|
|
26
|
-
src/
|
|
27
|
-
src/utf16/
|
|
30
|
+
src/utf8/validate.c
|
|
31
|
+
src/utf16/convert-to-latin1.c
|
|
32
|
+
src/utf16/convert-to-utf8.c
|
|
33
|
+
src/utf16/convert-to-utf32.c
|
|
34
|
+
src/utf16/length-from-latin1.c
|
|
35
|
+
src/utf16/length-from-utf8.c
|
|
36
|
+
src/utf16/length-from-utf32.c
|
|
28
37
|
src/utf16/validate.c
|
|
38
|
+
src/utf32/convert-to-latin1.c
|
|
39
|
+
src/utf32/convert-to-utf8.c
|
|
40
|
+
src/utf32/convert-to-utf16.c
|
|
41
|
+
src/utf32/length-from-latin1.c
|
|
42
|
+
src/utf32/length-from-utf8.c
|
|
43
|
+
src/utf32/length-from-utf16.c
|
|
44
|
+
src/utf32/validate.c
|
|
29
45
|
)
|
|
30
46
|
|
|
31
47
|
target_include_directories(
|
|
@@ -72,5 +88,6 @@ install(DIRECTORY include/utf DESTINATION include)
|
|
|
72
88
|
|
|
73
89
|
if(PROJECT_IS_TOP_LEVEL)
|
|
74
90
|
enable_testing()
|
|
91
|
+
|
|
75
92
|
add_subdirectory(test)
|
|
76
93
|
endif()
|
|
@@ -24,7 +24,10 @@ typedef struct utf8_string_view_s utf8_string_view_t;
|
|
|
24
24
|
struct utf8_string_s {
|
|
25
25
|
utf8_t *data;
|
|
26
26
|
size_t len;
|
|
27
|
-
|
|
27
|
+
union {
|
|
28
|
+
size_t cap;
|
|
29
|
+
utf8_t buf[8];
|
|
30
|
+
};
|
|
28
31
|
};
|
|
29
32
|
|
|
30
33
|
struct utf8_string_view_s {
|
|
@@ -34,9 +37,8 @@ struct utf8_string_view_s {
|
|
|
34
37
|
|
|
35
38
|
inline void
|
|
36
39
|
utf8_string_init (utf8_string_t *string) {
|
|
40
|
+
string->data = string->buf;
|
|
37
41
|
string->len = 0;
|
|
38
|
-
string->cap = 0;
|
|
39
|
-
string->data = NULL;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
inline utf8_string_view_t
|
|
@@ -46,41 +48,65 @@ utf8_string_view_init (const utf8_t *data, size_t len) {
|
|
|
46
48
|
|
|
47
49
|
inline void
|
|
48
50
|
utf8_string_destroy (utf8_string_t *string) {
|
|
49
|
-
free(string->data);
|
|
51
|
+
if (string->data != string->buf) free(string->data);
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
inline int
|
|
53
55
|
utf8_string_reserve (utf8_string_t *string, size_t len) {
|
|
54
|
-
size_t cap = string->cap;
|
|
56
|
+
size_t cap = string->data == string->buf ? sizeof(string->buf) : string->cap;
|
|
55
57
|
|
|
56
|
-
if (len
|
|
58
|
+
if (len <= cap) return 0;
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
|
61
|
+
len--;
|
|
62
|
+
len |= len >> 1;
|
|
63
|
+
len |= len >> 2;
|
|
64
|
+
len |= len >> 4;
|
|
65
|
+
len |= len >> 8;
|
|
66
|
+
len |= len >> 16;
|
|
67
|
+
if (sizeof(len) == 8) len |= len >> 32;
|
|
68
|
+
len++;
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
cap = len;
|
|
71
|
+
|
|
72
|
+
utf8_t *data;
|
|
63
73
|
|
|
64
|
-
|
|
74
|
+
if (string->data == string->buf) {
|
|
75
|
+
data = (utf8_t *) malloc(cap);
|
|
76
|
+
|
|
77
|
+
memcpy(data, string->data, string->len);
|
|
78
|
+
} else {
|
|
79
|
+
data = (utf8_t *) realloc(string->data, cap);
|
|
80
|
+
}
|
|
65
81
|
|
|
66
82
|
if (data == NULL) return -1;
|
|
67
83
|
|
|
68
|
-
string->cap = cap;
|
|
69
84
|
string->data = data;
|
|
85
|
+
string->cap = cap;
|
|
70
86
|
|
|
71
87
|
return 0;
|
|
72
88
|
}
|
|
73
89
|
|
|
74
90
|
inline int
|
|
75
91
|
utf8_string_shrink_to_fit (utf8_string_t *string) {
|
|
76
|
-
|
|
92
|
+
if (string->data == string->buf) return 0;
|
|
77
93
|
|
|
78
|
-
|
|
94
|
+
size_t cap = string->len;
|
|
79
95
|
|
|
80
|
-
if (
|
|
96
|
+
if (cap <= sizeof(string->buf)) {
|
|
97
|
+
memcpy(string->buf, string->data, cap);
|
|
81
98
|
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
free(string->data);
|
|
100
|
+
|
|
101
|
+
string->data = string->buf;
|
|
102
|
+
} else {
|
|
103
|
+
utf8_t *data = (utf8_t *) realloc(string->data, cap);
|
|
104
|
+
|
|
105
|
+
if (data == NULL) return -1;
|
|
106
|
+
|
|
107
|
+
string->data = data;
|
|
108
|
+
string->cap = cap;
|
|
109
|
+
}
|
|
84
110
|
|
|
85
111
|
return 0;
|
|
86
112
|
}
|
|
@@ -96,7 +122,7 @@ utf8_string_clear (utf8_string_t *string) {
|
|
|
96
122
|
}
|
|
97
123
|
|
|
98
124
|
inline bool
|
|
99
|
-
utf8_string_empty (utf8_string_t *string) {
|
|
125
|
+
utf8_string_empty (const utf8_string_t *string) {
|
|
100
126
|
return string->len == 0;
|
|
101
127
|
}
|
|
102
128
|
|
|
@@ -11,6 +11,9 @@ extern "C" {
|
|
|
11
11
|
|
|
12
12
|
typedef uint_least8_t utf8_t;
|
|
13
13
|
typedef uint_least16_t utf16_t;
|
|
14
|
+
typedef uint_least32_t utf32_t;
|
|
15
|
+
typedef uint_least8_t latin1_t;
|
|
16
|
+
typedef uint_least8_t ascii_t;
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* UTF-8
|
|
@@ -22,9 +25,21 @@ utf8_validate (const utf8_t *data, size_t len);
|
|
|
22
25
|
size_t
|
|
23
26
|
utf8_length_from_utf16le (const utf16_t *data, size_t len);
|
|
24
27
|
|
|
28
|
+
size_t
|
|
29
|
+
utf8_length_from_utf32 (const utf32_t *data, size_t len);
|
|
30
|
+
|
|
31
|
+
size_t
|
|
32
|
+
utf8_length_from_latin1 (const latin1_t *data, size_t len);
|
|
33
|
+
|
|
25
34
|
size_t
|
|
26
35
|
utf8_convert_to_utf16le (const utf8_t *data, size_t len, utf16_t *result);
|
|
27
36
|
|
|
37
|
+
size_t
|
|
38
|
+
utf8_convert_to_utf32 (const utf8_t *data, size_t len, utf32_t *result);
|
|
39
|
+
|
|
40
|
+
size_t
|
|
41
|
+
utf8_convert_to_latin1 (const utf8_t *data, size_t len, latin1_t *result);
|
|
42
|
+
|
|
28
43
|
/**
|
|
29
44
|
* UTF-16
|
|
30
45
|
*/
|
|
@@ -35,9 +50,81 @@ utf16le_validate (const utf16_t *data, size_t len);
|
|
|
35
50
|
size_t
|
|
36
51
|
utf16_length_from_utf8 (const utf8_t *data, size_t len);
|
|
37
52
|
|
|
53
|
+
size_t
|
|
54
|
+
utf16_length_from_utf32 (const utf32_t *data, size_t len);
|
|
55
|
+
|
|
56
|
+
size_t
|
|
57
|
+
utf16_length_from_latin1 (const latin1_t *data, size_t len);
|
|
58
|
+
|
|
38
59
|
size_t
|
|
39
60
|
utf16le_convert_to_utf8 (const utf16_t *data, size_t len, utf8_t *result);
|
|
40
61
|
|
|
62
|
+
size_t
|
|
63
|
+
utf16le_convert_to_utf32 (const utf16_t *data, size_t len, utf32_t *result);
|
|
64
|
+
|
|
65
|
+
size_t
|
|
66
|
+
utf16le_convert_to_latin1 (const utf16_t *data, size_t len, latin1_t *result);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* UTF-32
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
bool
|
|
73
|
+
utf32_validate (const utf32_t *data, size_t len);
|
|
74
|
+
|
|
75
|
+
size_t
|
|
76
|
+
utf32_length_from_utf8 (const utf8_t *data, size_t len);
|
|
77
|
+
|
|
78
|
+
size_t
|
|
79
|
+
utf32_length_from_utf16le (const utf16_t *data, size_t len);
|
|
80
|
+
|
|
81
|
+
size_t
|
|
82
|
+
utf32_length_from_latin1 (const latin1_t *data, size_t len);
|
|
83
|
+
|
|
84
|
+
size_t
|
|
85
|
+
utf32_convert_to_utf8 (const utf32_t *data, size_t len, utf8_t *result);
|
|
86
|
+
|
|
87
|
+
size_t
|
|
88
|
+
utf32_convert_to_utf16le (const utf32_t *data, size_t len, utf16_t *result);
|
|
89
|
+
|
|
90
|
+
size_t
|
|
91
|
+
utf32_convert_to_latin1 (const utf32_t *data, size_t len, latin1_t *result);
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Latin-1
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
size_t
|
|
98
|
+
latin1_length_from_utf8 (const utf8_t *data, size_t len);
|
|
99
|
+
|
|
100
|
+
size_t
|
|
101
|
+
latin1_length_from_utf16le (const utf16_t *data, size_t len);
|
|
102
|
+
|
|
103
|
+
size_t
|
|
104
|
+
latin1_length_from_utf32 (const utf32_t *data, size_t len);
|
|
105
|
+
|
|
106
|
+
size_t
|
|
107
|
+
latin1_convert_to_utf8 (const latin1_t *data, size_t len, utf8_t *result);
|
|
108
|
+
|
|
109
|
+
size_t
|
|
110
|
+
latin1_convert_to_utf16le (const latin1_t *data, size_t len, utf16_t *result);
|
|
111
|
+
|
|
112
|
+
size_t
|
|
113
|
+
latin1_convert_to_utf32 (const latin1_t *data, size_t len, utf32_t *result);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* ASCII
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
bool
|
|
120
|
+
ascii_validate (const ascii_t *data, size_t len);
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Strings
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
#include <utf/string.h>
|
|
127
|
+
|
|
41
128
|
#ifdef __cplusplus
|
|
42
129
|
}
|
|
43
130
|
#endif
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#include <stdbool.h>
|
|
2
|
+
#include <stddef.h>
|
|
3
|
+
#include <stdint.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
|
|
6
|
+
#include "../../include/utf.h"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Modified from https://github.com/simdutf/simdutf
|
|
10
|
+
*
|
|
11
|
+
* Copyright 2020 The simdutf authors
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License.
|
|
15
|
+
* You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
bool
|
|
27
|
+
ascii_validate (const ascii_t *data, size_t len) {
|
|
28
|
+
uint64_t pos = 0;
|
|
29
|
+
|
|
30
|
+
for (; pos + 16 <= len; pos += 16) {
|
|
31
|
+
uint64_t v1;
|
|
32
|
+
memcpy(&v1, data + pos, sizeof(uint64_t));
|
|
33
|
+
uint64_t v2;
|
|
34
|
+
memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
|
|
35
|
+
uint64_t v = v1 | v2;
|
|
36
|
+
if ((v & 0x8080808080808080) != 0) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (; pos < len; pos++) {
|
|
41
|
+
if (data[pos] >= 0b10000000) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#include <stddef.h>
|
|
2
|
+
#include <stdint.h>
|
|
3
|
+
#include <string.h>
|
|
4
|
+
|
|
5
|
+
#include "../../include/utf.h"
|
|
6
|
+
#include "../endianness.h"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Modified from https://github.com/simdutf/simdutf
|
|
10
|
+
*
|
|
11
|
+
* Copyright 2020 The simdutf authors
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License.
|
|
15
|
+
* You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
size_t
|
|
27
|
+
latin1_convert_to_utf16le (const latin1_t *data, size_t len, utf16_t *result) {
|
|
28
|
+
size_t pos = 0;
|
|
29
|
+
utf16_t *start = result;
|
|
30
|
+
|
|
31
|
+
while (pos < len) {
|
|
32
|
+
*result++ = utf_is_be() ? utf_swap_uint16(data[pos]) : data[pos];
|
|
33
|
+
pos++;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return result - start;
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#include <stddef.h>
|
|
2
|
+
#include <stdint.h>
|
|
3
|
+
#include <string.h>
|
|
4
|
+
|
|
5
|
+
#include "../../include/utf.h"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Modified from https://github.com/simdutf/simdutf
|
|
9
|
+
*
|
|
10
|
+
* Copyright 2020 The simdutf authors
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
size_t
|
|
26
|
+
latin1_convert_to_utf32 (const latin1_t *data, size_t len, utf32_t *result) {
|
|
27
|
+
utf32_t *start = result;
|
|
28
|
+
|
|
29
|
+
for (size_t i = 0; i < len; i++) {
|
|
30
|
+
*result++ = data[i];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return result - start;
|
|
34
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#include <stddef.h>
|
|
2
|
+
#include <stdint.h>
|
|
3
|
+
#include <string.h>
|
|
4
|
+
|
|
5
|
+
#include "../../include/utf.h"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Modified from https://github.com/simdutf/simdutf
|
|
9
|
+
*
|
|
10
|
+
* Copyright 2020 The simdutf authors
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
size_t
|
|
26
|
+
latin1_convert_to_utf8 (const latin1_t *data, size_t len, utf8_t *result) {
|
|
27
|
+
size_t pos = 0;
|
|
28
|
+
utf8_t *start = result;
|
|
29
|
+
|
|
30
|
+
while (pos < len) {
|
|
31
|
+
if (pos + 16 <= len) {
|
|
32
|
+
uint64_t v1;
|
|
33
|
+
memcpy(&v1, data + pos, sizeof(uint64_t));
|
|
34
|
+
uint64_t v2;
|
|
35
|
+
memcpy(&v2, data + pos + sizeof(uint64_t), sizeof(uint64_t));
|
|
36
|
+
uint64_t v = v1 | v2;
|
|
37
|
+
if ((v & 0x8080808080808080) == 0) {
|
|
38
|
+
size_t final_pos = pos + 16;
|
|
39
|
+
while (pos < final_pos) {
|
|
40
|
+
*result++ = data[pos];
|
|
41
|
+
pos++;
|
|
42
|
+
}
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
unsigned char byte = data[pos];
|
|
47
|
+
if ((byte & 0x80) == 0) {
|
|
48
|
+
*result++ = byte;
|
|
49
|
+
pos++;
|
|
50
|
+
} else {
|
|
51
|
+
*result++ = (byte >> 6) | 0b11000000;
|
|
52
|
+
*result++ = (byte & 0b111111) | 0b10000000;
|
|
53
|
+
pos++;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return result - start;
|
|
58
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#include <stddef.h>
|
|
2
|
+
|
|
3
|
+
#include "../../include/utf.h"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Modified from https://github.com/simdutf/simdutf
|
|
7
|
+
*
|
|
8
|
+
* Copyright 2020 The simdutf authors
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
size_t
|
|
24
|
+
latin1_length_from_utf16le (const utf16_t *data, size_t len) {
|
|
25
|
+
return len;
|
|
26
|
+
}
|