Add wuffs_base__base_16__encodeN

This commit is contained in:
Nigel Tao committed 2020-07-14 16:35:13 +10:00
1 parent 168f60a781
commit e917884d6c
4 files changed
+215 -3

No files matched your search

+81
View File
@@ -103,6 +103,11 @@ static const uint8_t wuffs_base__parse_number__hexadecimal_digits[256] = {
// 8 9 A B C D E F
};
static const uint8_t wuffs_base__private_implementation__encode_base16[16] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 0x00 ..= 0x07.
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, // 0x08 ..= 0x0F.
};
// --------
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //
@@ -493,6 +498,82 @@ wuffs_base__base_16__decode4(wuffs_base__slice_u8 dst,
return o;
}
WUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //
wuffs_base__base_16__encode2(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src,
bool src_closed,
uint32_t options) {
wuffs_base__transform__output o;
size_t dst_len2 = dst.len / 2;
size_t len;
if (dst_len2 < src.len) {
len = dst_len2;
o.status.repr = wuffs_base__suspension__short_write;
} else {
len = src.len;
if (!src_closed) {
o.status.repr = wuffs_base__suspension__short_read;
} else {
o.status.repr = NULL;
}
}
uint8_t* d = dst.ptr;
uint8_t* s = src.ptr;
size_t n = len;
while (n--) {
uint8_t c = *s;
d[0] = wuffs_base__private_implementation__encode_base16[c >> 4];
d[1] = wuffs_base__private_implementation__encode_base16[c & 0x0F];
d += 2;
s += 1;
}
o.num_dst = len * 2;
o.num_src = len;
return o;
}
WUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //
wuffs_base__base_16__encode4(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src,
bool src_closed,
uint32_t options) {
wuffs_base__transform__output o;
size_t dst_len4 = dst.len / 4;
size_t len;
if (dst_len4 < src.len) {
len = dst_len4;
o.status.repr = wuffs_base__suspension__short_write;
} else {
len = src.len;
if (!src_closed) {
o.status.repr = wuffs_base__suspension__short_read;
} else {
o.status.repr = NULL;
}
}
uint8_t* d = dst.ptr;
uint8_t* s = src.ptr;
size_t n = len;
while (n--) {
uint8_t c = *s;
d[0] = '\\';
d[1] = 'x';
d[2] = wuffs_base__private_implementation__encode_base16[c >> 4];
d[3] = wuffs_base__private_implementation__encode_base16[c & 0x0F];
d += 4;
s += 1;
}
o.num_dst = len * 4;
o.num_src = len;
return o;
}
// ---------------- Base-64
// The two base-64 alphabets, std and url, differ only in the last two codes.
+24
View File
@@ -389,6 +389,30 @@ wuffs_base__base_16__decode4(wuffs_base__slice_u8 dst,
bool src_closed,
uint32_t options);
// wuffs_base__base_16__encode2 converts "jk" to "6A6B", where e.g. 'j' is
// U+006A. There are 2 dst bytes for every src byte.
//
// For modular builds that divide the base module into sub-modules, using this
// function requires the WUFFS_CONFIG__MODULE__BASE__INTCONV sub-module, not
// just WUFFS_CONFIG__MODULE__BASE__CORE.
WUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //
wuffs_base__base_16__encode2(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src,
bool src_closed,
uint32_t options);
// wuffs_base__base_16__encode4 converts "jk" to "\\x6A\\x6B", where e.g. 'j'
// is U+006A. There are 4 dst bytes for every src byte.
//
// For modular builds that divide the base module into sub-modules, using this
// function requires the WUFFS_CONFIG__MODULE__BASE__INTCONV sub-module, not
// just WUFFS_CONFIG__MODULE__BASE__CORE.
WUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //
wuffs_base__base_16__encode2(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src,
bool src_closed,
uint32_t options);
// ---------------- Base-64
// Options (bitwise or'ed together) for wuffs_base__base_64__xxx functions.
+5 -3
View File
@@ -170,7 +170,7 @@ const BaseIntConvSubmoduleC = "" +
" // 0xB8 ..= 0xBF.\n\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC0 ..= 0xC7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC8 ..= 0xCF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD0 ..= 0xD7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD8 ..= 0xDF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE0 ..= 0xE7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE8 ..= 0xEF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xF0 ..= 0xF7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xF8 ..= 0xFF.\n // 0 1 2 3 4 5 6 7\n // 8 9 A B C D E F\n};\n\nstatic const uint8_t wuffs_base__parse_number__hexadecimal_digits[256] = {\n // 0 1 2 3 4 5 6 7\n // 8 9 A B C D E F\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 ..= 0x07.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x08 ..= 0x0F.\n 0x00, " +
"0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x10 ..= 0x17.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x18 ..= 0x1F.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x20 ..= 0x27.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x28 ..= 0x2F.\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, // 0x30 ..= 0x37. '0'-'7'.\n 0x88, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x38 ..= 0x3F. '8'-'9'.\n\n 0x00, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x00, // 0x40 ..= 0x47. 'A'-'F'.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x48 ..= 0x4F.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x50 ..= 0x57.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x58 ..= 0x5F.\n 0x00, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x00, // 0x60 ..= 0x67. 'a'-'f'.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x68 ..= 0x6F.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x70 ..= 0x77.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x78 ..= 0x7F.\n\n " +
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x80 ..= 0x87.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x88 ..= 0x8F.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x90 ..= 0x97.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x98 ..= 0x9F.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xA0 ..= 0xA7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xA8 ..= 0xAF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xB0 ..= 0xB7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xB8 ..= 0xBF.\n\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC0 ..= 0xC7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC8 ..= 0xCF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD0 ..= 0xD7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD8 ..= 0xDF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE0 ..= 0xE7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE8 ..= 0xEF.\n 0x00, 0x00, 0x00, 0x00, 0x0" +
"0, 0x00, 0x00, 0x00, // 0xF0 ..= 0xF7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xF8 ..= 0xFF.\n // 0 1 2 3 4 5 6 7\n // 8 9 A B C D E F\n};\n\n" +
"0, 0x00, 0x00, 0x00, // 0xF0 ..= 0xF7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xF8 ..= 0xFF.\n // 0 1 2 3 4 5 6 7\n // 8 9 A B C D E F\n};\n\nstatic const uint8_t wuffs_base__private_implementation__encode_base16[16] = {\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 0x00 ..= 0x07.\n 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, // 0x08 ..= 0x0F.\n};\n\n" +
"" +
"// --------\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //\nwuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n\n bool negative = false;\n if (p >= q) {\n goto fail_bad_argument;\n } else if (*p == '-') {\n p++;\n negative = true;\n } else if (*p == '+') {\n p++;\n }\n\n do {\n wuffs_base__result_u64 r = wuffs_base__parse_number_u64(\n wuffs_base__make_slice_u8(p, (size_t)(q - p)), options);\n if (r.status.repr != NULL) {\n wuffs_base__result_i64 ret;\n ret.status.repr = r.status.repr;\n ret.value = 0;\n return ret;\n } else if (negative) {\n if (r.value > 0x8000000000000000) {\n goto fail_out_of_bounds;\n }\n wuffs_base__result_i64 ret;\n ret.status.repr = NULL;\n ret.value = -(int64_t)(r.value);\n return ret;\n } else if (r.value > 0x7FFFFFFFFFFF" +
"FFFF) {\n goto fail_out_of_bounds;\n } else {\n wuffs_base__result_i64 ret;\n ret.status.repr = NULL;\n ret.value = +(int64_t)(r.value);\n return ret;\n }\n } while (0);\n\nfail_bad_argument:\n do {\n wuffs_base__result_i64 ret;\n ret.status.repr = wuffs_base__error__bad_argument;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_out_of_bounds:\n do {\n wuffs_base__result_i64 ret;\n ret.status.repr = wuffs_base__error__out_of_bounds;\n ret.value = 0;\n return ret;\n } while (0);\n}\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //\nwuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n\n if (p >= q) {\n goto fail_bad_argument;\n\n } else if (*p == '0') {\n p++;\n if (p >= q) {\n goto ok_zero;\n }\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n " +
@@ -185,7 +185,8 @@ const BaseIntConvSubmoduleC = "" +
"" +
"// ---------------- Base-16\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //\nwuffs_base__base_16__decode2(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src,\n bool src_closed,\n uint32_t options) {\n wuffs_base__transform__output o;\n size_t src_len2 = src.len / 2;\n size_t len;\n if (dst.len < src_len2) {\n len = dst.len;\n o.status.repr = wuffs_base__suspension__short_write;\n } else {\n len = src_len2;\n if (!src_closed) {\n o.status.repr = wuffs_base__suspension__short_read;\n } else if (src.len & 1) {\n o.status.repr = wuffs_base__error__bad_data;\n } else {\n o.status.repr = NULL;\n }\n }\n\n uint8_t* d = dst.ptr;\n uint8_t* s = src.ptr;\n size_t n = len;\n\n while (n--) {\n *d = (uint8_t)((wuffs_base__parse_number__hexadecimal_digits[s[0]] << 4) |\n (wuffs_base__parse_number__hexadecimal_digits[s[1]] & 0x0F));\n d += 1;\n s += 2;\n }\n\n o.num_dst = len;\n o.num_s" +
"rc = len * 2;\n return o;\n}\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //\nwuffs_base__base_16__decode4(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src,\n bool src_closed,\n uint32_t options) {\n wuffs_base__transform__output o;\n size_t src_len4 = src.len / 4;\n size_t len = dst.len < src_len4 ? dst.len : src_len4;\n if (dst.len < src_len4) {\n len = dst.len;\n o.status.repr = wuffs_base__suspension__short_write;\n } else {\n len = src_len4;\n if (!src_closed) {\n o.status.repr = wuffs_base__suspension__short_read;\n } else if (src.len & 1) {\n o.status.repr = wuffs_base__error__bad_data;\n } else {\n o.status.repr = NULL;\n }\n }\n\n uint8_t* d = dst.ptr;\n uint8_t* s = src.ptr;\n size_t n = len;\n\n while (n--) {\n *d = (uint8_t)((wuffs_base__parse_number__hexadecimal_digits[s[2]] << 4) |\n (wuffs_base__parse_number__hexadecimal_digits[s[3]] & 0x0F));\n d += 1;\n " +
" s += 4;\n }\n\n o.num_dst = len;\n o.num_src = len * 4;\n return o;\n}\n\n" +
" s += 4;\n }\n\n o.num_dst = len;\n o.num_src = len * 4;\n return o;\n}\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //\nwuffs_base__base_16__encode2(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src,\n bool src_closed,\n uint32_t options) {\n wuffs_base__transform__output o;\n size_t dst_len2 = dst.len / 2;\n size_t len;\n if (dst_len2 < src.len) {\n len = dst_len2;\n o.status.repr = wuffs_base__suspension__short_write;\n } else {\n len = src.len;\n if (!src_closed) {\n o.status.repr = wuffs_base__suspension__short_read;\n } else {\n o.status.repr = NULL;\n }\n }\n\n uint8_t* d = dst.ptr;\n uint8_t* s = src.ptr;\n size_t n = len;\n\n while (n--) {\n uint8_t c = *s;\n d[0] = wuffs_base__private_implementation__encode_base16[c >> 4];\n d[1] = wuffs_base__private_implementation__encode_base16[c & 0x0F];\n d += 2;\n s += 1;\n }\n\n o.num_dst = len * 2;\n o.num_src = len;\n return o;\n}\n\nWUFFS_BA" +
"SE__MAYBE_STATIC wuffs_base__transform__output //\nwuffs_base__base_16__encode4(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src,\n bool src_closed,\n uint32_t options) {\n wuffs_base__transform__output o;\n size_t dst_len4 = dst.len / 4;\n size_t len;\n if (dst_len4 < src.len) {\n len = dst_len4;\n o.status.repr = wuffs_base__suspension__short_write;\n } else {\n len = src.len;\n if (!src_closed) {\n o.status.repr = wuffs_base__suspension__short_read;\n } else {\n o.status.repr = NULL;\n }\n }\n\n uint8_t* d = dst.ptr;\n uint8_t* s = src.ptr;\n size_t n = len;\n\n while (n--) {\n uint8_t c = *s;\n d[0] = '\\\\';\n d[1] = 'x';\n d[2] = wuffs_base__private_implementation__encode_base16[c >> 4];\n d[3] = wuffs_base__private_implementation__encode_base16[c & 0x0F];\n d += 4;\n s += 1;\n }\n\n o.num_dst = len * 4;\n o.num_src = len;\n return o;\n}\n\n" +
"" +
"// ---------------- Base-64\n\n// The two base-64 alphabets, std and url, differ only in the last two codes.\n// - std: \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\"\n// - url: \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\"\n\nstatic const uint8_t wuffs_base__base_64__decode_std[256] = {\n // 0 1 2 3 4 5 6 7\n // 8 9 A B C D E F\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x00 ..= 0x07.\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x08 ..= 0x0F.\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x10 ..= 0x17.\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x18 ..= 0x1F.\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x20 ..= 0x27.\n 0x80, 0x80, 0x80, 0x3E, 0x80, 0x80, 0x80, 0x3F, // 0x28 ..= 0x2F.\n 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, // 0x30 ..= 0x37.\n 0x3C, 0x3D, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x38 ..= 0x3F.\n\n 0x80, 0x00, 0x01, 0x02," +
" 0x03, 0x04, 0x05, 0x06, // 0x40 ..= 0x47.\n 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, // 0x48 ..= 0x4F.\n 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, // 0x50 ..= 0x57.\n 0x17, 0x18, 0x19, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x58 ..= 0x5F.\n 0x80, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, // 0x60 ..= 0x67.\n 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, // 0x68 ..= 0x6F.\n 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, // 0x70 ..= 0x77.\n 0x31, 0x32, 0x33, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x78 ..= 0x7F.\n\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x80 ..= 0x87.\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x88 ..= 0x8F.\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x90 ..= 0x97.\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0x98 ..= 0x9F.\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0xA0 ..= 0xA7.\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0xA8 ..= 0xAF.\n 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // " +
@@ -538,7 +539,8 @@ const BaseStrConvPublicH = "" +
"just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC size_t //\nwuffs_base__render_number_u64(wuffs_base__slice_u8 dst,\n uint64_t x,\n uint32_t options);\n\n" +
"" +
"// ---------------- Base-16\n\n// Options (bitwise or'ed together) for wuffs_base__base_16__xxx functions.\n\n#define WUFFS_BASE__BASE_16__DEFAULT_OPTIONS ((uint32_t)0x00000000)\n\n// wuffs_base__base_16__decode2 converts \"6A6b\" to \"jk\", where e.g. 'j' is\n// U+006A. There are 2 src bytes for every dst byte.\n//\n// It assumes that the src bytes are two hexadecimal digits (0-9, A-F, a-f),\n// repeated. It may write nonsense bytes if not, although it will not read or\n// write out of bounds.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__INTCONV sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //\nwuffs_base__base_16__decode2(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src,\n bool src_closed,\n uint32_t options);\n\n// wuffs_base__base_16__decode4 converts both \"\\\\x6A\\\\x6b\" and \"??6a??6B\" " +
"to\n// \"jk\", where e.g. 'j' is U+006A. There are 4 src bytes for every dst byte.\n//\n// It assumes that the src bytes are two ignored bytes and then two hexadecimal\n// digits (0-9, A-F, a-f), repeated. It may write nonsense bytes if not,\n// although it will not read or write out of bounds.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__INTCONV sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //\nwuffs_base__base_16__decode4(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src,\n bool src_closed,\n uint32_t options);\n\n" +
"to\n// \"jk\", where e.g. 'j' is U+006A. There are 4 src bytes for every dst byte.\n//\n// It assumes that the src bytes are two ignored bytes and then two hexadecimal\n// digits (0-9, A-F, a-f), repeated. It may write nonsense bytes if not,\n// although it will not read or write out of bounds.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__INTCONV sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //\nwuffs_base__base_16__decode4(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src,\n bool src_closed,\n uint32_t options);\n\n// wuffs_base__base_16__encode2 converts \"jk\" to \"6A6B\", where e.g. 'j' is\n// U+006A. There are 2 dst bytes for every src byte.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__INTCONV" +
" sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //\nwuffs_base__base_16__encode2(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src,\n bool src_closed,\n uint32_t options);\n\n// wuffs_base__base_16__encode4 converts \"jk\" to \"\\\\x6A\\\\x6B\", where e.g. 'j'\n// is U+006A. There are 4 dst bytes for every src byte.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__INTCONV sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //\nwuffs_base__base_16__encode2(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src,\n bool src_closed,\n uint32_t options);\n\n" +
"" +
"// ---------------- Base-64\n\n// Options (bitwise or'ed together) for wuffs_base__base_64__xxx functions.\n\n#define WUFFS_BASE__BASE_64__DEFAULT_OPTIONS ((uint32_t)0x00000000)\n\n// WUFFS_BASE__BASE_64__DECODE_ALLOW_PADDING means that, when decoding base-64,\n// the input may (but does not need to) be padded with '=' bytes so that the\n// overall encoded length in bytes is a multiple of 4. A successful decoding\n// will return a num_src that includes those padding bytes.\n//\n// Excess padding (e.g. three final '='s) will be rejected as bad data.\n#define WUFFS_BASE__BASE_64__DECODE_ALLOW_PADDING ((uint32_t)0x00000001)\n\n// WUFFS_BASE__BASE_64__ENCODE_EMIT_PADDING means that, when encoding base-64,\n// the output will be padded with '=' bytes so that the overall encoded length\n// in bytes is a multiple of 4.\n#define WUFFS_BASE__BASE_64__ENCODE_EMIT_PADDING ((uint32_t)0x00000002)\n\n// WUFFS_BASE__BASE_64__URL_ALPHABET means that, for base-64, the URL-friendly\n// and file-name-friendly alphabet be used, as per RFC 4648 sect" +
"ion 5. When\n// this option bit is off, the standard alphabet from section 4 is used.\n#define WUFFS_BASE__BASE_64__URL_ALPHABET ((uint32_t)0x00000100)\n\n// wuffs_base__base_64__decode transforms base-64 encoded bytes from src to\n// arbitrary bytes in dst.\n//\n// It will not permit line breaks or other whitespace in src. Filtering those\n// out is the responsibility of the caller.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__INTCONV sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //\nwuffs_base__base_64__decode(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src,\n bool src_closed,\n uint32_t options);\n\n// wuffs_base__base_64__encode transforms arbitrary bytes from src to base-64\n// encoded bytes in dst.\n//\n// For modular builds that divide the base module into sub-modules, using this" +
+105
View File
@@ -4308,6 +4308,30 @@ wuffs_base__base_16__decode4(wuffs_base__slice_u8 dst,
bool src_closed,
uint32_t options);
// wuffs_base__base_16__encode2 converts "jk" to "6A6B", where e.g. 'j' is
// U+006A. There are 2 dst bytes for every src byte.
//
// For modular builds that divide the base module into sub-modules, using this
// function requires the WUFFS_CONFIG__MODULE__BASE__INTCONV sub-module, not
// just WUFFS_CONFIG__MODULE__BASE__CORE.
WUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //
wuffs_base__base_16__encode2(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src,
bool src_closed,
uint32_t options);
// wuffs_base__base_16__encode4 converts "jk" to "\\x6A\\x6B", where e.g. 'j'
// is U+006A. There are 4 dst bytes for every src byte.
//
// For modular builds that divide the base module into sub-modules, using this
// function requires the WUFFS_CONFIG__MODULE__BASE__INTCONV sub-module, not
// just WUFFS_CONFIG__MODULE__BASE__CORE.
WUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //
wuffs_base__base_16__encode2(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src,
bool src_closed,
uint32_t options);
// ---------------- Base-64
// Options (bitwise or'ed together) for wuffs_base__base_64__xxx functions.
@@ -11967,6 +11991,11 @@ static const uint8_t wuffs_base__parse_number__hexadecimal_digits[256] = {
// 8 9 A B C D E F
};
static const uint8_t wuffs_base__private_implementation__encode_base16[16] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 0x00 ..= 0x07.
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, // 0x08 ..= 0x0F.
};
// --------
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //
@@ -12357,6 +12386,82 @@ wuffs_base__base_16__decode4(wuffs_base__slice_u8 dst,
return o;
}
WUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //
wuffs_base__base_16__encode2(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src,
bool src_closed,
uint32_t options) {
wuffs_base__transform__output o;
size_t dst_len2 = dst.len / 2;
size_t len;
if (dst_len2 < src.len) {
len = dst_len2;
o.status.repr = wuffs_base__suspension__short_write;
} else {
len = src.len;
if (!src_closed) {
o.status.repr = wuffs_base__suspension__short_read;
} else {
o.status.repr = NULL;
}
}
uint8_t* d = dst.ptr;
uint8_t* s = src.ptr;
size_t n = len;
while (n--) {
uint8_t c = *s;
d[0] = wuffs_base__private_implementation__encode_base16[c >> 4];
d[1] = wuffs_base__private_implementation__encode_base16[c & 0x0F];
d += 2;
s += 1;
}
o.num_dst = len * 2;
o.num_src = len;
return o;
}
WUFFS_BASE__MAYBE_STATIC wuffs_base__transform__output //
wuffs_base__base_16__encode4(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src,
bool src_closed,
uint32_t options) {
wuffs_base__transform__output o;
size_t dst_len4 = dst.len / 4;
size_t len;
if (dst_len4 < src.len) {
len = dst_len4;
o.status.repr = wuffs_base__suspension__short_write;
} else {
len = src.len;
if (!src_closed) {
o.status.repr = wuffs_base__suspension__short_read;
} else {
o.status.repr = NULL;
}
}
uint8_t* d = dst.ptr;
uint8_t* s = src.ptr;
size_t n = len;
while (n--) {
uint8_t c = *s;
d[0] = '\\';
d[1] = 'x';
d[2] = wuffs_base__private_implementation__encode_base16[c >> 4];
d[3] = wuffs_base__private_implementation__encode_base16[c & 0x0F];
d += 4;
s += 1;
}
o.num_dst = len * 4;
o.num_src = len;
return o;
}
// ---------------- Base-64
// The two base-64 alphabets, std and url, differ only in the last two codes.