Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › crypto › codecs › base64_hex_ct › hex › decodeAny Private Function decodeAny Doc Source Private Function std.crypto.codecs.base64_hex_ct.hex.decodeAny
fn decodeAny (
bin : []u8 ,
encoded : []const u8 ,
ignored_chars : ?StaticBitSet (256 ),
) error Params bin : []u8 encoded : []const u8 ignored_chars : ?StaticBitSet (256 ) File crypto/codecs/base64_hex_ct.zig: 106
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 fn decodeAny (
bin : []u8 ,
encoded : []const u8 ,
ignored_chars : ?StaticBitSet (256 ),
) error { NoSpaceLeft , InvalidCharacter , InvalidPadding }![]const u8 {
var bin_pos : usize = 0 ;
var state : bool = false ;
var c_acc : u8 = 0 ;
for (encoded ) |c | {
const c_num = c ^ 48 ;
const c_num0 : u8 = @truncate ((@as (u16 , c_num ) -% 10 ) >> 8 );
const c_alpha : u8 = (c & ~@as (u8 , 32 )) -% 55 ;
const c_alpha0 : u8 = @truncate (((@as (u16 , c_alpha ) -% 10 ) ^ (@as (u16 , c_alpha ) -% 16 )) >> 8 );
if ((c_num0 | c_alpha0 ) == 0 ) {
if (ignored_chars ) |set | {
if (set .isSet (c )) {
continue ;
}
}
return error .InvalidCharacter ;
}
const c_val = (c_num0 & c_num ) | (c_alpha0 & c_alpha );
if (bin_pos >= bin .len ) {
return error .NoSpaceLeft ;
}
if (!state ) {
c_acc = c_val << 4 ;
} else {
bin [bin_pos ] = c_acc | c_val ;
bin_pos += 1 ;
}
state = !state ;
}
if (state ) {
return error .InvalidPadding ;
}
return bin [0 ..bin_pos ];
}