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 › zon › Serializer › EmitCodepointLiterals › emitAsCodepoint Private Function emitAsCodepoint Doc Source Private Function std.zon.Serializer.EmitCodepointLiterals.emitAsCodepoint
fn emitAsCodepoint (self : @This (), val : anytype ) ?u21 Params File zon/Serializer.zig: 81
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 fn emitAsCodepoint (self : @This (), val : anytype ) ?u21 {
// Rule out incompatible integer types
switch (@typeInfo (@TypeOf (val ))) {
.int => |int_info | if (int_info .signedness == .signed or int_info .bits > 21 ) {
return null ;
},
.comptime_int => {},
else => comptime unreachable ,
}
// Return null if the value shouldn't be printed as a Unicode codepoint, or the value casted
// to a u21 if it should.
switch (self ) {
.always => {
const c = std .math .cast (u21 , val ) orelse return null ;
if (!std .unicode .utf8ValidCodepoint (c )) return null ;
return c ;
},
.printable_ascii => {
const c = std .math .cast (u8 , val ) orelse return null ;
if (!std .ascii .isPrint (c )) return null ;
return c ;
},
.never => {
return null ;
},
}
}
If the value should be emitted as a Unicode codepoint, return it as a u21.