bare-buffer 2.5.9 → 2.5.11
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/CMakeLists.txt +4 -11
- package/package.json +3 -8
- package/prebuilds/android-arm/bare-buffer.bare +0 -0
- package/prebuilds/android-arm64/bare-buffer.bare +0 -0
- package/prebuilds/android-ia32/bare-buffer.bare +0 -0
- package/prebuilds/android-x64/bare-buffer.bare +0 -0
- package/prebuilds/darwin-arm64/bare-buffer.bare +0 -0
- package/prebuilds/darwin-x64/bare-buffer.bare +0 -0
- package/prebuilds/ios-arm64/bare-buffer.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-buffer.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-buffer.bare +0 -0
- package/prebuilds/linux-arm64/bare-buffer.bare +0 -0
- package/prebuilds/linux-x64/bare-buffer.bare +0 -0
- package/prebuilds/win32-arm64/bare-buffer.bare +0 -0
- package/prebuilds/win32-x64/bare-buffer.bare +0 -0
- package/vendor/libbase64/CMakeLists.txt +0 -70
- package/vendor/libbase64/include/base64.h +0 -22
- package/vendor/libbase64/src/base64.c +0 -107
- package/vendor/libhex/CMakeLists.txt +0 -71
- package/vendor/libhex/include/hex.h +0 -22
- package/vendor/libhex/src/hex.c +0 -67
- package/vendor/libutf/CMakeLists.txt +0 -93
- package/vendor/libutf/include/utf/string.h +0 -786
- package/vendor/libutf/include/utf.h +0 -132
- package/vendor/libutf/src/ascii/validate.c +0 -47
- package/vendor/libutf/src/endianness.c +0 -19
- package/vendor/libutf/src/endianness.h +0 -54
- package/vendor/libutf/src/latin1/convert-to-utf16.c +0 -37
- package/vendor/libutf/src/latin1/convert-to-utf32.c +0 -34
- package/vendor/libutf/src/latin1/convert-to-utf8.c +0 -58
- package/vendor/libutf/src/latin1/length-from-utf16.c +0 -26
- package/vendor/libutf/src/latin1/length-from-utf32.c +0 -26
- package/vendor/libutf/src/latin1/length-from-utf8.c +0 -34
- package/vendor/libutf/src/utf16/convert-to-latin1.c +0 -41
- package/vendor/libutf/src/utf16/convert-to-utf32.c +0 -56
- package/vendor/libutf/src/utf16/convert-to-utf8.c +0 -75
- package/vendor/libutf/src/utf16/length-from-latin1.c +0 -26
- package/vendor/libutf/src/utf16/length-from-utf32.c +0 -33
- package/vendor/libutf/src/utf16/length-from-utf8.c +0 -38
- package/vendor/libutf/src/utf16/validate.c +0 -53
- package/vendor/libutf/src/utf32/convert-to-latin1.c +0 -40
- package/vendor/libutf/src/utf32/convert-to-utf16.c +0 -56
- package/vendor/libutf/src/utf32/convert-to-utf8.c +0 -71
- package/vendor/libutf/src/utf32/length-from-latin1.c +0 -26
- package/vendor/libutf/src/utf32/length-from-utf16.c +0 -35
- package/vendor/libutf/src/utf32/length-from-utf8.c +0 -35
- package/vendor/libutf/src/utf32/validate.c +0 -39
- package/vendor/libutf/src/utf8/convert-to-latin1.c +0 -70
- package/vendor/libutf/src/utf8/convert-to-utf16.c +0 -95
- package/vendor/libutf/src/utf8/convert-to-utf32.c +0 -110
- package/vendor/libutf/src/utf8/length-from-latin1.c +0 -32
- package/vendor/libutf/src/utf8/length-from-utf16.c +0 -44
- package/vendor/libutf/src/utf8/length-from-utf32.c +0 -35
- package/vendor/libutf/src/utf8/string.c +0 -149
- package/vendor/libutf/src/utf8/validate.c +0 -107
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
utf16_length_from_utf32 (const utf32_t *data, size_t len) {
|
|
25
|
-
size_t counter = 0;
|
|
26
|
-
|
|
27
|
-
for (size_t i = 0; i < len; i++) {
|
|
28
|
-
counter++;
|
|
29
|
-
counter += data[i] > 0xffff;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return counter;
|
|
33
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
#include <stddef.h>
|
|
2
|
-
#include <stdint.h>
|
|
3
|
-
|
|
4
|
-
#include "../../include/utf.h"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Modified from https://github.com/simdutf/simdutf
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2020 The simdutf authors
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
size_t
|
|
25
|
-
utf16_length_from_utf8 (const utf8_t *data, size_t len) {
|
|
26
|
-
size_t counter = 0;
|
|
27
|
-
|
|
28
|
-
for (size_t i = 0; i < len; i++) {
|
|
29
|
-
if ((int8_t) data[i] > -65) {
|
|
30
|
-
counter++;
|
|
31
|
-
}
|
|
32
|
-
if (data[i] >= 240) {
|
|
33
|
-
counter++;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return counter;
|
|
38
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
#include <stdbool.h>
|
|
2
|
-
#include <stddef.h>
|
|
3
|
-
#include <stdint.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
|
-
bool
|
|
27
|
-
utf16le_validate (const utf16_t *data, size_t len) {
|
|
28
|
-
uint64_t pos = 0;
|
|
29
|
-
uint16_t word, diff;
|
|
30
|
-
|
|
31
|
-
while (pos < len) {
|
|
32
|
-
word = utf_is_be() ? utf_swap_uint16(data[pos]) : data[pos];
|
|
33
|
-
if ((word & 0xf800) == 0xd800) {
|
|
34
|
-
if (pos + 1 >= len) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
diff = word - 0xd800;
|
|
38
|
-
if (diff > 0x3ff) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
word = utf_is_be() ? utf_swap_uint16(data[pos + 1]) : data[pos + 1];
|
|
42
|
-
diff = word - 0xdc00;
|
|
43
|
-
if (diff > 0x3ff) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
pos += 2;
|
|
47
|
-
} else {
|
|
48
|
-
pos++;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#include <stddef.h>
|
|
2
|
-
#include <stdint.h>
|
|
3
|
-
|
|
4
|
-
#include "../../include/utf.h"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Modified from https://github.com/simdutf/simdutf
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2020 The simdutf authors
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
size_t
|
|
25
|
-
utf32_convert_to_latin1 (const utf32_t *data, size_t len, latin1_t *result) {
|
|
26
|
-
size_t pos = 0;
|
|
27
|
-
uint32_t word, overflow = 0;
|
|
28
|
-
latin1_t *start = result;
|
|
29
|
-
|
|
30
|
-
while (pos < len) {
|
|
31
|
-
word = data[pos];
|
|
32
|
-
overflow |= word;
|
|
33
|
-
*result++ = word & 0xff;
|
|
34
|
-
pos++;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (overflow & 0xffffff00) return 0;
|
|
38
|
-
|
|
39
|
-
return result - start;
|
|
40
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
#include <stddef.h>
|
|
2
|
-
#include <stdint.h>
|
|
3
|
-
|
|
4
|
-
#include "../../include/utf.h"
|
|
5
|
-
#include "../endianness.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
|
-
utf32_convert_to_utf16le (const utf32_t *data, size_t len, utf16_t *result) {
|
|
27
|
-
size_t pos = 0;
|
|
28
|
-
uint32_t word;
|
|
29
|
-
utf16_t *start = result;
|
|
30
|
-
|
|
31
|
-
while (pos < len) {
|
|
32
|
-
word = data[pos];
|
|
33
|
-
if ((word & 0xffff0000) == 0) {
|
|
34
|
-
if (word >= 0xd800 && word <= 0xdfff) {
|
|
35
|
-
return 0;
|
|
36
|
-
}
|
|
37
|
-
*result++ = utf_is_be() ? utf_swap_uint16(data[pos]) : data[pos];
|
|
38
|
-
} else {
|
|
39
|
-
if (word > 0x10ffff) {
|
|
40
|
-
return 0;
|
|
41
|
-
}
|
|
42
|
-
word -= 0x10000;
|
|
43
|
-
uint16_t high_surrogate = 0xd800 + (word >> 10);
|
|
44
|
-
uint16_t low_surrogate = 0xdc00 + (word & 0x3ff);
|
|
45
|
-
if (utf_is_be()) {
|
|
46
|
-
high_surrogate = utf_swap_uint16(high_surrogate);
|
|
47
|
-
low_surrogate = utf_swap_uint16(low_surrogate);
|
|
48
|
-
}
|
|
49
|
-
*result++ = high_surrogate;
|
|
50
|
-
*result++ = low_surrogate;
|
|
51
|
-
}
|
|
52
|
-
pos++;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return result - start;
|
|
56
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
utf32_convert_to_utf8 (const utf32_t *data, size_t len, utf8_t *result) {
|
|
27
|
-
size_t pos = 0;
|
|
28
|
-
uint32_t word;
|
|
29
|
-
utf8_t *start = result;
|
|
30
|
-
|
|
31
|
-
while (pos < len) {
|
|
32
|
-
if (pos + 2 <= len) {
|
|
33
|
-
uint64_t v;
|
|
34
|
-
memcpy(&v, data + pos, sizeof(uint64_t));
|
|
35
|
-
if ((v & 0xffffff80ffffff80) == 0) {
|
|
36
|
-
*result++ = data[pos];
|
|
37
|
-
*result++ = data[pos + 1];
|
|
38
|
-
pos += 2;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
word = data[pos];
|
|
43
|
-
if ((word & 0xffffff80) == 0) {
|
|
44
|
-
*result++ = word;
|
|
45
|
-
pos++;
|
|
46
|
-
} else if ((word & 0xfffff800) == 0) {
|
|
47
|
-
*result++ = (word >> 6) | 0b11000000;
|
|
48
|
-
*result++ = (word & 0b111111) | 0b10000000;
|
|
49
|
-
pos++;
|
|
50
|
-
} else if ((word & 0xffff0000) == 0) {
|
|
51
|
-
if (word >= 0xd800 && word <= 0xdfff) {
|
|
52
|
-
return 0;
|
|
53
|
-
}
|
|
54
|
-
*result++ = (word >> 12) | 0b11100000;
|
|
55
|
-
*result++ = ((word >> 6) & 0b111111) | 0b10000000;
|
|
56
|
-
*result++ = (word & 0b111111) | 0b10000000;
|
|
57
|
-
pos++;
|
|
58
|
-
} else {
|
|
59
|
-
if (word > 0x10ffff) {
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
*result++ = (word >> 18) | 0b11110000;
|
|
63
|
-
*result++ = ((word >> 12) & 0b111111) | 0b10000000;
|
|
64
|
-
*result++ = ((word >> 6) & 0b111111) | 0b10000000;
|
|
65
|
-
*result++ = (word & 0b111111) | 0b10000000;
|
|
66
|
-
pos++;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return result - start;
|
|
71
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
utf32_length_from_latin1 (const utf8_t *data, size_t len) {
|
|
25
|
-
return len;
|
|
26
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#include <stddef.h>
|
|
2
|
-
#include <stdint.h>
|
|
3
|
-
|
|
4
|
-
#include "../../include/utf.h"
|
|
5
|
-
#include "../endianness.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
|
-
utf32_length_from_utf16le (const utf16_t *data, size_t len) {
|
|
27
|
-
size_t counter = 0;
|
|
28
|
-
|
|
29
|
-
for (size_t i = 0; i < len; i++) {
|
|
30
|
-
uint16_t word = utf_is_be() ? utf_swap_uint16(data[i]) : data[i];
|
|
31
|
-
counter += ((word & 0xfc00) != 0xdc00);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return counter;
|
|
35
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#include <stddef.h>
|
|
2
|
-
#include <stdint.h>
|
|
3
|
-
|
|
4
|
-
#include "../../include/utf.h"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Modified from https://github.com/simdutf/simdutf
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2020 The simdutf authors
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
size_t
|
|
25
|
-
utf32_length_from_utf8 (const utf8_t *data, size_t len) {
|
|
26
|
-
size_t counter = 0;
|
|
27
|
-
|
|
28
|
-
for (size_t i = 0; i < len; i++) {
|
|
29
|
-
if ((int8_t) data[i] > -65) {
|
|
30
|
-
counter++;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return counter;
|
|
35
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
#include <stdbool.h>
|
|
2
|
-
#include <stddef.h>
|
|
3
|
-
#include <stdint.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
|
-
bool
|
|
26
|
-
utf32_validate (const utf32_t *data, size_t len) {
|
|
27
|
-
uint64_t pos = 0;
|
|
28
|
-
uint32_t word;
|
|
29
|
-
|
|
30
|
-
while (pos < len) {
|
|
31
|
-
word = data[pos];
|
|
32
|
-
if (word > 0x10ffff || (word >= 0xd800 && word <= 0xdfff)) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
pos++;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
utf8_convert_to_latin1 (const utf8_t *data, size_t len, latin1_t *result) {
|
|
27
|
-
size_t pos = 0;
|
|
28
|
-
latin1_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
|
-
uint8_t leading_byte = data[pos];
|
|
47
|
-
if (leading_byte < 0b10000000) {
|
|
48
|
-
*result++ = leading_byte;
|
|
49
|
-
pos++;
|
|
50
|
-
} else if ((leading_byte & 0b11100000) == 0b11000000) {
|
|
51
|
-
if (pos + 1 >= len) {
|
|
52
|
-
return 0;
|
|
53
|
-
}
|
|
54
|
-
if ((data[pos + 1] & 0b11000000) != 0b10000000) {
|
|
55
|
-
return 0;
|
|
56
|
-
}
|
|
57
|
-
uint32_t code_point = ((leading_byte & 0b00011111) << 6) |
|
|
58
|
-
(data[pos + 1] & 0b00111111);
|
|
59
|
-
if (code_point < 0x80 || 0xff < code_point) {
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
*result++ = code_point;
|
|
63
|
-
pos += 2;
|
|
64
|
-
} else {
|
|
65
|
-
return 0;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return result - start;
|
|
70
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
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
|
-
utf8_convert_to_utf16le (const utf8_t *data, size_t len, utf16_t *result) {
|
|
28
|
-
size_t pos = 0;
|
|
29
|
-
utf16_t *start = result;
|
|
30
|
-
|
|
31
|
-
while (pos < len) {
|
|
32
|
-
if (pos + 8 <= len) {
|
|
33
|
-
uint64_t v;
|
|
34
|
-
memcpy(&v, data + pos, sizeof(uint64_t));
|
|
35
|
-
if ((v & 0x8080808080808080) == 0) {
|
|
36
|
-
size_t final_pos = pos + 8;
|
|
37
|
-
while (pos < final_pos) {
|
|
38
|
-
*result++ = utf_is_be() ? utf_swap_uint16(data[pos]) : data[pos];
|
|
39
|
-
pos++;
|
|
40
|
-
}
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
uint8_t leading_byte = data[pos];
|
|
45
|
-
if (leading_byte < 0b10000000) {
|
|
46
|
-
*result++ = utf_is_be() ? utf_swap_uint16(leading_byte) : leading_byte;
|
|
47
|
-
pos++;
|
|
48
|
-
} else if ((leading_byte & 0b11100000) == 0b11000000) {
|
|
49
|
-
if (pos + 1 >= len) {
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
uint16_t code_point = ((leading_byte & 0b00011111) << 6) |
|
|
53
|
-
(data[pos + 1] & 0b00111111);
|
|
54
|
-
if (utf_is_be()) {
|
|
55
|
-
code_point = utf_swap_uint16(code_point);
|
|
56
|
-
}
|
|
57
|
-
*result++ = code_point;
|
|
58
|
-
pos += 2;
|
|
59
|
-
} else if ((leading_byte & 0b11110000) == 0b11100000) {
|
|
60
|
-
if (pos + 2 >= len) {
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
uint16_t code_point = ((leading_byte & 0b00001111) << 12) |
|
|
64
|
-
((data[pos + 1] & 0b00111111) << 6) |
|
|
65
|
-
(data[pos + 2] & 0b00111111);
|
|
66
|
-
if (utf_is_be()) {
|
|
67
|
-
code_point = utf_swap_uint16(code_point);
|
|
68
|
-
}
|
|
69
|
-
*result++ = code_point;
|
|
70
|
-
pos += 3;
|
|
71
|
-
} else if ((leading_byte & 0b11111000) == 0b11110000) {
|
|
72
|
-
if (pos + 3 >= len) {
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
uint32_t code_point = ((leading_byte & 0b00000111) << 18) |
|
|
76
|
-
((data[pos + 1] & 0b00111111) << 12) |
|
|
77
|
-
((data[pos + 2] & 0b00111111) << 6) |
|
|
78
|
-
(data[pos + 3] & 0b00111111);
|
|
79
|
-
code_point -= 0x10000;
|
|
80
|
-
uint16_t high_surrogate = 0xd800 + (code_point >> 10);
|
|
81
|
-
uint16_t low_surrogate = 0xdc00 + (code_point & 0x3ff);
|
|
82
|
-
if (utf_is_be()) {
|
|
83
|
-
high_surrogate = utf_swap_uint16(high_surrogate);
|
|
84
|
-
low_surrogate = utf_swap_uint16(low_surrogate);
|
|
85
|
-
}
|
|
86
|
-
*result++ = high_surrogate;
|
|
87
|
-
*result++ = low_surrogate;
|
|
88
|
-
pos += 4;
|
|
89
|
-
} else {
|
|
90
|
-
return 0;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return result - start;
|
|
95
|
-
}
|