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 › asn1 › Oid › fromDot Public Function fromDot Doc Source Public Function std.crypto.codecs.asn1.Oid.fromDot
pub fn fromDot (dot_notation : []const u8 , out : []u8 ) InitError !Oid Params dot_notation : []const u8 out : []u8 File crypto/codecs/asn1/Oid.zig: 9
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 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 () };
}