Skip to content

Commit

Permalink
std::encoding::base32: get destination slice for the Encode and Decod…
Browse files Browse the repository at this point in the history
…e functions
  • Loading branch information
mertcandav committed Jul 27, 2024
1 parent 764c16e commit 6996edb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions std/encoding/base32/base32.jule
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ static t32 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
// Standard byte for padding.
const paddingByte = '='

// Encodes source bytes with standard base32 table.
// Encodes source bytes into dest with standard base32 table.
// Returns encoded base32 bytes if success, nil slice if not.
// Adds padding if pad is true.
fn Encode(src: []byte, pad: bool): []byte {
let mut dest: []byte = nil
// Algorithm will call the append function to append dest.
fn Encode(mut dest: []byte, src: []byte, pad: bool): []byte {
let mut bits: u64 = 0
let mut buffer: u32 = 0
let p = &t32[0]
Expand Down Expand Up @@ -58,11 +58,11 @@ fn Encode(src: []byte, pad: bool): []byte {
ret dest
}

// Decodes source bytes with standard base32 table.
// Decodes source bytes into dest with standard base32 table.
// Returns decoded bytes if success, nil slice if not.
// Detects padding by default, no required padding specification.
fn Decode(src: []byte): []byte {
let mut dest: []byte = nil
// Algorithm will call the append function to append dest.
fn Decode(mut dest: []byte, src: []byte): []byte {
let mut buffer: u32 = 0
let mut bits: u64 = 0
for _, b in src {
Expand Down
4 changes: 2 additions & 2 deletions std/encoding/base32/base32_test.jule
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static encodeDecodeMap = [
#test
fn testEncode(t: &T) {
for _, case in encodeDecodeMap {
let r = Encode(case[0], true)
let r = Encode(nil, case[0], true)
let d = case[1]
if len(r) != len(d) {
t.Fail()
Expand All @@ -47,7 +47,7 @@ fn testEncode(t: &T) {
#test
fn testDecode(t: &T) {
for _, case in encodeDecodeMap {
let r = Decode(case[1])
let r = Decode(nil, case[1])
let d = case[0]
if len(r) != len(d) {
t.Fail()
Expand Down

0 comments on commit 6996edb

Please sign in to comment.