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 › zig › ZonGen › appendIdentStr Private Function appendIdentStr Doc Source Private Function std.zig.ZonGen.appendIdentStr
fn appendIdentStr (zg : *ZonGen , ident_token : Ast .TokenIndex ) error Params File zig/ZonGen.zig: 452
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490 fn appendIdentStr (zg : *ZonGen , ident_token : Ast .TokenIndex ) error { OutOfMemory , BadString }!u32 {
const gpa = zg .gpa ;
const tree = zg .tree ;
assert (tree .tokenTag (ident_token ) == .identifier );
const ident_name = tree .tokenSlice (ident_token );
if (!mem .startsWith (u8 , ident_name , "@" )) {
const start = zg .string_bytes .items .len ;
try zg .string_bytes .appendSlice (gpa , ident_name );
return @intCast (start );
}
const offset = 1 ;
const start : u32 = @intCast (zg .string_bytes .items .len );
const raw_string = zg .tree .tokenSlice (ident_token )[offset ..];
try zg .string_bytes .ensureUnusedCapacity (gpa , raw_string .len );
const result = r : {
var aw : Writer .Allocating = .fromArrayList (gpa , &zg .string_bytes );
defer zg .string_bytes = aw .toArrayList ();
break :r std .zig .string_literal .parseWrite (&aw .writer , raw_string ) catch |err | switch (err ) {
error .WriteFailed => return error .OutOfMemory ,
};
};
switch (result ) {
.success => {},
.failure => |err | {
try zg .lowerStrLitError (err , ident_token , raw_string , offset );
return error .BadString ;
},
}
const slice = zg .string_bytes .items [start ..];
if (mem .findScalar (u8 , slice , 0 ) != null ) {
try zg .addErrorTok (ident_token , "identifier cannot contain null bytes" , .{});
return error .BadString ;
} else if (slice .len == 0 ) {
try zg .addErrorTok (ident_token , "identifier cannot be empty" , .{});
return error .BadString ;
}
return start ;
}