DoxigAlpha

init

Function parameters

Parameters

#
alphabet_chars:[64]u8
pad_char:?u8

Base64 codecs

Types

#
Codecs
Base64 codecs

Error sets in this namespace

Error Sets

#

The Base64 alphabet defined in

Values

#
standard_alphabet_chars
The Base64 alphabet defined in
standard
Standard Base64 codecs, with padding, as defined in
standard_no_pad
Standard Base64 codecs, without padding, as defined in
url_safe_alphabet_chars
The URL-safe Base64 alphabet defined in
url_safe
URL-safe Base64 codecs, with padding, as defined in
url_safe_no_pad
URL-safe Base64 codecs, without padding, as defined in

Source

Implementation

#
pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Decoder {
    var result = Base64Decoder{
        .char_to_index = [_]u8{invalid_char} ** 256,
        .fast_char_to_index = .{[_]u32{invalid_char_tst} ** 256} ** 4,
        .pad_char = pad_char,
    };

    var char_in_alphabet = [_]bool{false} ** 256;
    for (alphabet_chars, 0..) |c, i| {
        assert(!char_in_alphabet[c]);
        assert(pad_char == null or c != pad_char.?);

        const ci = @as(u32, @intCast(i));
        result.fast_char_to_index[0][c] = ci << 2;
        result.fast_char_to_index[1][c] = (ci >> 4) | ((ci & 0x0f) << 12);
        result.fast_char_to_index[2][c] = ((ci & 0x3) << 22) | ((ci & 0x3c) << 6);
        result.fast_char_to_index[3][c] = ci << 16;

        result.char_to_index[c] = @as(u8, @intCast(i));
        char_in_alphabet[c] = true;
    }
    return result;
}