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 › compiler/ › Maker.zig › sanitizeExampleName
sanitizeExampleName
Maker.sanitizeExampleName
fn sanitizeExampleName (arena : Allocator , bytes : []const u8 ) error
File
Code
fn sanitizeExampleName (arena : Allocator , bytes : []const u8 ) error {OutOfMemory }![]const u8 {
var result : std .ArrayList (u8 ) = .empty ;
for (bytes , 0 ..) |byte , i | switch (byte ) {
'0' ...'9' => {
if (i == 0 ) try result .append (arena , '_' );
try result .append (arena , byte );
},
'_' , 'a' ...'z' , 'A' ...'Z' => try result .append (arena , byte ),
'-' , '.' , ' ' => try result .append (arena , '_' ),
else => continue ,
};
if (!std .zig .isValidId (result .items )) return "foo" ;
if (result .items .len > Package .Manifest .max_name_len )
result .shrinkRetainingCapacity (Package .Manifest .max_name_len );
return result .toOwnedSlice (arena );
}