@ohos-ports/bare-buffer 3.7.1-beta.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/LICENSE +201 -0
- package/README.md +26 -0
- package/binding.c +1077 -0
- package/binding.gyp +32 -0
- package/binding.js +1 -0
- package/build/Release/bare_buffer.node +0 -0
- package/deps/libbase64/.clang-format +10 -0
- package/deps/libbase64/.gitattributes +1 -0
- package/deps/libbase64/.github/workflows/integrate.yml +45 -0
- package/deps/libbase64/.github/workflows/nightly.yml +28 -0
- package/deps/libbase64/.prettierrc +1 -0
- package/deps/libbase64/CMakeLists.txt +71 -0
- package/deps/libbase64/LICENSE +201 -0
- package/deps/libbase64/NOTICE +13 -0
- package/deps/libbase64/README.md +11 -0
- package/deps/libbase64/include/base64.h +323 -0
- package/deps/libbase64/package.json +25 -0
- package/deps/libbase64/src/base64.c +22 -0
- package/deps/libbase64/test/CMakeLists.txt +31 -0
- package/deps/libbase64/test/decode-invalid.c +35 -0
- package/deps/libbase64/test/decode-length.c +23 -0
- package/deps/libbase64/test/decode.c +36 -0
- package/deps/libbase64/test/encode-length.c +22 -0
- package/deps/libbase64/test/encode.c +42 -0
- package/deps/libbase64/test/fuzz/CMakeLists.txt +18 -0
- package/deps/libbase64/test/fuzz/decode/utf16le.c +53 -0
- package/deps/libbase64/test/fuzz/decode/utf8.c +47 -0
- package/deps/libbase64/test/fuzz/encode/utf16le.c +56 -0
- package/deps/libbase64/test/fuzz/encode/utf8.c +56 -0
- package/deps/libhex/.clang-format +10 -0
- package/deps/libhex/.gitattributes +1 -0
- package/deps/libhex/.github/workflows/integrate.yml +45 -0
- package/deps/libhex/.github/workflows/nightly.yml +28 -0
- package/deps/libhex/.prettierrc +1 -0
- package/deps/libhex/CMakeLists.txt +72 -0
- package/deps/libhex/LICENSE +201 -0
- package/deps/libhex/NOTICE +13 -0
- package/deps/libhex/README.md +11 -0
- package/deps/libhex/include/hex.h +163 -0
- package/deps/libhex/package.json +25 -0
- package/deps/libhex/src/hex.c +16 -0
- package/deps/libhex/test/CMakeLists.txt +31 -0
- package/deps/libhex/test/decode-invalid.c +37 -0
- package/deps/libhex/test/decode-length.c +23 -0
- package/deps/libhex/test/decode.c +25 -0
- package/deps/libhex/test/encode-length.c +22 -0
- package/deps/libhex/test/encode.c +25 -0
- package/deps/libhex/test/fuzz/CMakeLists.txt +18 -0
- package/deps/libhex/test/fuzz/decode/utf16le.c +53 -0
- package/deps/libhex/test/fuzz/decode/utf8.c +47 -0
- package/deps/libhex/test/fuzz/encode/utf16le.c +36 -0
- package/deps/libhex/test/fuzz/encode/utf8.c +36 -0
- package/deps/libutf/.clang-format +10 -0
- package/deps/libutf/.gitattributes +1 -0
- package/deps/libutf/.github/workflows/integrate.yml +45 -0
- package/deps/libutf/.github/workflows/nightly.yml +28 -0
- package/deps/libutf/.prettierrc +1 -0
- package/deps/libutf/CMakeLists.txt +105 -0
- package/deps/libutf/LICENSE +201 -0
- package/deps/libutf/NOTICE +13 -0
- package/deps/libutf/README.md +11 -0
- package/deps/libutf/include/utf/string.h +1655 -0
- package/deps/libutf/include/utf.h +132 -0
- package/deps/libutf/package.json +24 -0
- package/deps/libutf/src/ascii/validate.c +47 -0
- package/deps/libutf/src/endianness.c +19 -0
- package/deps/libutf/src/endianness.h +54 -0
- package/deps/libutf/src/latin1/convert-to-utf16.c +37 -0
- package/deps/libutf/src/latin1/convert-to-utf32.c +34 -0
- package/deps/libutf/src/latin1/convert-to-utf8.c +58 -0
- package/deps/libutf/src/latin1/length-from-utf16.c +26 -0
- package/deps/libutf/src/latin1/length-from-utf32.c +26 -0
- package/deps/libutf/src/latin1/length-from-utf8.c +34 -0
- package/deps/libutf/src/utf16/convert-to-latin1.c +41 -0
- package/deps/libutf/src/utf16/convert-to-utf32.c +56 -0
- package/deps/libutf/src/utf16/convert-to-utf8.c +80 -0
- package/deps/libutf/src/utf16/length-from-latin1.c +26 -0
- package/deps/libutf/src/utf16/length-from-utf32.c +33 -0
- package/deps/libutf/src/utf16/length-from-utf8.c +38 -0
- package/deps/libutf/src/utf16/validate.c +53 -0
- package/deps/libutf/src/utf32/convert-to-latin1.c +40 -0
- package/deps/libutf/src/utf32/convert-to-utf16.c +56 -0
- package/deps/libutf/src/utf32/convert-to-utf8.c +71 -0
- package/deps/libutf/src/utf32/length-from-latin1.c +26 -0
- package/deps/libutf/src/utf32/length-from-utf16.c +35 -0
- package/deps/libutf/src/utf32/length-from-utf8.c +35 -0
- package/deps/libutf/src/utf32/string.c +149 -0
- package/deps/libutf/src/utf32/validate.c +39 -0
- package/deps/libutf/src/utf8/convert-to-latin1.c +70 -0
- package/deps/libutf/src/utf8/convert-to-utf16.c +95 -0
- package/deps/libutf/src/utf8/convert-to-utf32.c +110 -0
- package/deps/libutf/src/utf8/length-from-latin1.c +32 -0
- package/deps/libutf/src/utf8/length-from-utf16.c +48 -0
- package/deps/libutf/src/utf8/length-from-utf32.c +35 -0
- package/deps/libutf/src/utf8/string.c +149 -0
- package/deps/libutf/src/utf8/validate.c +107 -0
- package/deps/libutf/test/CMakeLists.txt +56 -0
- package/deps/libutf/test/fuzz/CMakeLists.txt +26 -0
- package/deps/libutf/test/fuzz/corpus/.gitignore +2 -0
- package/deps/libutf/test/fuzz/crashes/.gitignore +2 -0
- package/deps/libutf/test/fuzz/latin1/convert-to-utf16.c +32 -0
- package/deps/libutf/test/fuzz/latin1/convert-to-utf32.c +32 -0
- package/deps/libutf/test/fuzz/latin1/convert-to-utf8.c +33 -0
- package/deps/libutf/test/fuzz/utf16/convert-to-latin1.c +36 -0
- package/deps/libutf/test/fuzz/utf16/convert-to-utf32.c +38 -0
- package/deps/libutf/test/fuzz/utf16/convert-to-utf8.c +38 -0
- package/deps/libutf/test/fuzz/utf32/convert-to-latin1.c +36 -0
- package/deps/libutf/test/fuzz/utf32/convert-to-utf16.c +38 -0
- package/deps/libutf/test/fuzz/utf32/convert-to-utf8.c +38 -0
- package/deps/libutf/test/fuzz/utf8/convert-to-latin1.c +33 -0
- package/deps/libutf/test/fuzz/utf8/convert-to-utf16.c +35 -0
- package/deps/libutf/test/fuzz/utf8/convert-to-utf32.c +35 -0
- package/deps/libutf/test/utf16/utf8-convert.c +45 -0
- package/deps/libutf/test/utf16/utf8-length.c +41 -0
- package/deps/libutf/test/utf16/validate-invalid.c +50 -0
- package/deps/libutf/test/utf16/validate.c +32 -0
- package/deps/libutf/test/utf32/string-append.c +74 -0
- package/deps/libutf/test/utf32/string-compare.c +108 -0
- package/deps/libutf/test/utf32/string-erase.c +79 -0
- package/deps/libutf/test/utf32/string-index.c +102 -0
- package/deps/libutf/test/utf32/string-insert.c +92 -0
- package/deps/libutf/test/utf32/string-last-index.c +71 -0
- package/deps/libutf/test/utf32/string-prepend.c +51 -0
- package/deps/libutf/test/utf32/string-replace.c +88 -0
- package/deps/libutf/test/utf32/string-reserve.c +99 -0
- package/deps/libutf/test/utf32/string-substring.c +93 -0
- package/deps/libutf/test/utf8/latin1-convert.c +23 -0
- package/deps/libutf/test/utf8/string-append.c +23 -0
- package/deps/libutf/test/utf8/string-compare.c +67 -0
- package/deps/libutf/test/utf8/string-erase.c +75 -0
- package/deps/libutf/test/utf8/string-index.c +99 -0
- package/deps/libutf/test/utf8/string-last-index.c +68 -0
- package/deps/libutf/test/utf8/string-prepend.c +23 -0
- package/deps/libutf/test/utf8/string-replace.c +74 -0
- package/deps/libutf/test/utf8/string-reserve.c +51 -0
- package/deps/libutf/test/utf8/string-substring.c +68 -0
- package/deps/libutf/test/utf8/utf16-convert.c +32 -0
- package/deps/libutf/test/utf8/utf16-length.c +29 -0
- package/deps/libutf/test/utf8/validate-invalid.c +26 -0
- package/deps/libutf/test/utf8/validate.c +21 -0
- package/global.d.ts +21 -0
- package/global.js +6 -0
- package/index.d.ts +769 -0
- package/index.js +1339 -0
- package/lib/ascii.js +36 -0
- package/lib/base64.js +25 -0
- package/lib/base64url.js +25 -0
- package/lib/checked.js +23 -0
- package/lib/constants.d.ts +7 -0
- package/lib/constants.js +3 -0
- package/lib/hex.js +20 -0
- package/lib/latin1.js +14 -0
- package/lib/utf16le.js +20 -0
- package/lib/utf8.js +18 -0
- package/package.json +64 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#include <assert.h>
|
|
2
|
+
#include <string.h>
|
|
3
|
+
|
|
4
|
+
#include "../../include/utf.h"
|
|
5
|
+
|
|
6
|
+
#define test_convert(string, len, expected, written) \
|
|
7
|
+
{ \
|
|
8
|
+
utf16_t result[len]; \
|
|
9
|
+
assert(utf8_convert_to_utf16le((utf8_t *) string, len, result) == written); \
|
|
10
|
+
assert(memcmp(expected, result, written) == 0); \
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
int
|
|
14
|
+
main() {
|
|
15
|
+
// ASCII character 'A'
|
|
16
|
+
test_convert("\x41", 1, "\x41\x00", 1);
|
|
17
|
+
|
|
18
|
+
// Greek capital letter 'Ω'
|
|
19
|
+
test_convert("\xce\xa9", 2, "\xa9\x03", 1);
|
|
20
|
+
|
|
21
|
+
// Snowman symbol '☃'
|
|
22
|
+
test_convert("\xe2\x98\x83", 3, "\x03\x26", 1);
|
|
23
|
+
|
|
24
|
+
// Chinese character 'ä¸'
|
|
25
|
+
test_convert("\xe4\xb8\xad", 3, "\x2d\x4e", 1);
|
|
26
|
+
|
|
27
|
+
// Face with tears of joy emoji '😂'
|
|
28
|
+
test_convert("\xf0\x9f\x98\x82", 4, "\x3d\xd8\x02\xde", 2);
|
|
29
|
+
|
|
30
|
+
// Multiple characters "AΩ☃ä¸ðŸ˜‚"
|
|
31
|
+
test_convert("\x41\xce\xa9\xe2\x98\x83\xe4\xb8\xad\xf0\x9f\x98\x82", 13, "\x41\x00\xa9\x03\x03\x26\x2d\x4e\x3d\xd8\x02\xde", 6);
|
|
32
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#include <assert.h>
|
|
2
|
+
|
|
3
|
+
#include "../../include/utf.h"
|
|
4
|
+
|
|
5
|
+
#define test_length(string, len, expected) \
|
|
6
|
+
{ \
|
|
7
|
+
assert(utf16_length_from_utf8((utf8_t *) string, len) == expected); \
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
int
|
|
11
|
+
main() {
|
|
12
|
+
// ASCII character 'A'
|
|
13
|
+
test_length("\x41", 1, 1);
|
|
14
|
+
|
|
15
|
+
// Greek capital letter 'Ω'
|
|
16
|
+
test_length("\xce\xa9", 2, 1);
|
|
17
|
+
|
|
18
|
+
// Snowman symbol '☃'
|
|
19
|
+
test_length("\xe2\x98\x83", 3, 1);
|
|
20
|
+
|
|
21
|
+
// Chinese character 'ä¸'
|
|
22
|
+
test_length("\xe4\xb8\xad", 3, 1);
|
|
23
|
+
|
|
24
|
+
// Face with tears of joy emoji '😂'
|
|
25
|
+
test_length("\xf0\x9f\x98\x82", 4, 2);
|
|
26
|
+
|
|
27
|
+
// Multiple characters "AΩ☃ä¸ðŸ˜‚"
|
|
28
|
+
test_length("\x41\xce\xa9\xe2\x98\x83\xe4\xb8\xad\xf0\x9f\x98\x82", 13, 6);
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#include <assert.h>
|
|
2
|
+
|
|
3
|
+
#include "../../include/utf.h"
|
|
4
|
+
|
|
5
|
+
#define test_validate(string, len) \
|
|
6
|
+
{ \
|
|
7
|
+
assert(!utf8_validate((utf8_t *) string, len)); \
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
int
|
|
11
|
+
main() {
|
|
12
|
+
test_validate("\x80", 1); // The byte is 10000000 in binary. The first bit suggests it's a continuation byte, but there's no start byte.
|
|
13
|
+
test_validate("\xc3", 1); // This byte indicates the start of a 2-byte sequence, but it's missing the second byte.
|
|
14
|
+
test_validate("\xc0\x80", 2); // Overlong encoding of NULL character, which should be 0x00 in UTF-8
|
|
15
|
+
test_validate("\xc3\xa9\xa8", 3); // This starts as a valid 2-byte sequence, but then has an unexpected third byte.
|
|
16
|
+
test_validate("\x80\x80", 2); // This sequence starts with a continuation byte, which is not allowed.
|
|
17
|
+
test_validate("\xfe", 1); // This byte indicates the start of a sequence of length 7, but UTF-8 only supports up to 4-byte sequences.
|
|
18
|
+
test_validate("\xe2\x82", 2); // This start byte indicates a 3-byte sequence, but only one additional byte is provided.
|
|
19
|
+
test_validate("\xf4\x90\x80\x80", 4); // This sequence decodes to U+110000, which is beyond the U+10FFFF limit of Unicode.
|
|
20
|
+
test_validate("\xed\xa0\x80", 3); // This sequence decodes to U+D800, a high surrogate.
|
|
21
|
+
test_validate("\xed\xbf\xbf", 3); // This sequence decodes to U+DFFF, a low surrogate.
|
|
22
|
+
test_validate("\xe2\x82\xc0", 3); // The last byte should be a continuation byte (10xxxxxx), but it's a start byte (110xxxxx).
|
|
23
|
+
test_validate("\x80\xc2", 2); // This sequence starts with a continuation byte, which is not allowed.
|
|
24
|
+
test_validate("\xf8\x88\x88\x88\x88", 5); // UTF-8 only supports up to 4-byte sequences.
|
|
25
|
+
test_validate("\xfc\x84\x84\x84\x84\x84", 6); // UTF-8 only supports up to 4-byte sequences.
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#include <assert.h>
|
|
2
|
+
|
|
3
|
+
#include "../../include/utf.h"
|
|
4
|
+
|
|
5
|
+
#define test_validate(string, len) \
|
|
6
|
+
{ \
|
|
7
|
+
assert(utf8_validate((utf8_t *) string, len)); \
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
int
|
|
11
|
+
main() {
|
|
12
|
+
test_validate("a", 1); // Single ASCII character
|
|
13
|
+
test_validate("Hello, World!", 13); // ASCII characters
|
|
14
|
+
test_validate("\xc3\xa9", 2); // Single 2-byte UTF-8 character
|
|
15
|
+
test_validate("\xc3\xa9\xc3\xa8\xc3\xaa\xc3\xab\xc3\xaf", 10); // String of 2-byte UTF-8 characters
|
|
16
|
+
test_validate("\xe2\x82\xac", 3); // Single 3-byte UTF-8 character
|
|
17
|
+
test_validate("\xe2\x82\xac\xe2\x89\xa1\xe2\x9c\x93", 9); // String of 3-byte UTF-8 characters
|
|
18
|
+
test_validate("\xf0\x9f\x98\x80", 4); // Single 4-byte UTF-8 character
|
|
19
|
+
test_validate("\xf0\x9f\x98\x80\xf0\x9f\x98\x81\xf0\x9f\x98\x82", 12); // String of 4-byte UTF-8 characters
|
|
20
|
+
test_validate("a \xc3\xa9 \xe2\x82\xac \xf0\x9f\x98\x80", 13); // Mix of all
|
|
21
|
+
}
|
package/global.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as buffer from '.'
|
|
2
|
+
|
|
3
|
+
type BufferConstructor = typeof buffer.Buffer
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
/** A fixed-length view of binary data, backed by an `ArrayBuffer` and extending `Uint8Array`. */
|
|
7
|
+
type Buffer = buffer.Buffer
|
|
8
|
+
|
|
9
|
+
const Buffer: BufferConstructor
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Decode a base64-encoded string into a Latin-1 binary string.
|
|
13
|
+
* @param data - The base64-encoded string to decode.
|
|
14
|
+
*/
|
|
15
|
+
const atob: typeof buffer.atob
|
|
16
|
+
/**
|
|
17
|
+
* Encode a Latin-1 binary string into a base64 string.
|
|
18
|
+
* @param data - The value to encode; non-strings are coerced with `String()`.
|
|
19
|
+
*/
|
|
20
|
+
const btoa: typeof buffer.btoa
|
|
21
|
+
}
|