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 library itself.
Zig › std/ › crypto/ › codecs/ › asn1/ › Oid.zig › fromDot
fromDot
Oid.fromDot
pub fn fromDot (dot_notation : []const u8 , out : []u8 ) InitError !Oid
File
Code
pub fn fromDot (dot_notation : []const u8 , out : []u8 ) InitError !Oid {
var split = std .mem .splitScalar (u8 , dot_notation , '.' );
const first_str = split .next () orelse return error .MissingPrefix ;
const second_str = split .next () orelse return error .MissingPrefix ;
const first = try std .fmt .parseInt (u8 , first_str , 10 );
const second = try std .fmt .parseInt (u8 , second_str , 10 );
var writer : std .Io .Writer = .fixed (out );
try writer .writeByte (first * 40 + second );
var i : usize = 1 ;
while (split .next ()) |s | {
var parsed = try std .fmt .parseUnsigned (Arc , s , 10 );
const n_bytes = if (parsed == 0 ) 0 else std .math .log (Arc , encoding_base , parsed );
for (0 ..n_bytes ) |j | {
const place = std .math .pow (Arc , encoding_base , n_bytes - @as (Arc , @intCast (j )));
const digit : u8 = @intCast (@divFloor (parsed , place ));
try writer .writeByte (digit | 0x80 );
parsed -= digit * place ;
i += 1 ;
}
try writer .writeByte (@intCast (parsed ));
i += 1 ;
}
return .{ .encoded = writer .buffered () };
}