diff options
| author | gingerBill <bill@gingerbill.org> | 2020-09-23 17:17:14 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-09-23 17:17:14 +0100 |
| commit | fc4fdd588e5bd0c45d04c792267a0f4434c6a38e (patch) | |
| tree | 59bcddc60248dd78ed1155dd7a6ae7ae3de2e07e /core/encoding/base64/base64.odin | |
| parent | 4844dd4d96f0921f44e70c9960d3e4476aad7115 (diff) | |
Remove usage of `do` in core library
Diffstat (limited to 'core/encoding/base64/base64.odin')
| -rw-r--r-- | core/encoding/base64/base64.odin | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/core/encoding/base64/base64.odin b/core/encoding/base64/base64.odin index 2724aa0e5..744d28903 100644 --- a/core/encoding/base64/base64.odin +++ b/core/encoding/base64/base64.odin @@ -2,46 +2,48 @@ package base64 // @note(zh): Encoding utility for Base64 // A secondary param can be used to supply a custom alphabet to -// @link(encode) and a matching decoding table to @link(decode). +// @link(encode) and a matching decoding table to @link(decode). // If none is supplied it just uses the standard Base64 alphabet. // Incase your specific version does not use padding, you may // truncate it from the encoded output. ENC_TABLE := [64]byte { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', - 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', + 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; PADDING :: '='; DEC_TABLE := [128]int { - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 62, -1, -1, -1, 63, - 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, -1, -1, -1, -1, -1, -1, - -1, 0, 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, - 23, 24, 25, -1, -1, -1, -1, -1, - -1, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 62, -1, -1, -1, 63, + 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, -1, -1, -1, -1, -1, + -1, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 }; encode :: proc(data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocator) -> string #no_bounds_check { length := len(data); - if length == 0 do return ""; + if length == 0 { + return ""; + } out_length := ((4 * length / 3) + 3) &~ 3; out := make([]byte, out_length, allocator); @@ -51,8 +53,8 @@ encode :: proc(data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocato for i, d := 0, 0; i < length; i, d = i + 3, d + 4 { c0, c1, c2 = int(data[i]), -1, -1; - if i + 1 < length do c1 = int(data[i + 1]); - if i + 2 < length do c2 = int(data[i + 2]); + if i + 1 < length { c1 = int(data[i + 1]); } + if i + 2 < length { c2 = int(data[i + 2]); } block = (c0 << 16) | (max(c1, 0) << 8) | max(c2, 0); @@ -66,7 +68,9 @@ encode :: proc(data: []byte, ENC_TBL := ENC_TABLE, allocator := context.allocato decode :: proc(data: string, DEC_TBL := DEC_TABLE, allocator := context.allocator) -> []byte #no_bounds_check { length := len(data); - if length == 0 do return []byte{}; + if length == 0 { + return nil; + } pad_count := data[length - 1] == PADDING ? (data[length - 2] == PADDING ? 2 : 1) : 0; out_length := ((length * 6) >> 3) - pad_count; |