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/ › zig/ › AstGen.zig › strLitNodeAsString
strLitNodeAsString
AstGen.strLitNodeAsString
fn strLitNodeAsString (astgen : *AstGen , node : Ast .Node .Index ) !IndexSlice
File
Code
fn strLitNodeAsString (astgen : *AstGen , node : Ast .Node .Index ) !IndexSlice {
const tree = astgen .tree ;
const start , const end = tree .nodeData (node ).token_and_token ;
const gpa = astgen .gpa ;
const string_bytes = &astgen .string_bytes ;
const str_index = string_bytes .items .len ;
var tok_i = start ;
{
const slice = tree .tokenSlice (tok_i );
const line_bytes = slice [2 ..];
try string_bytes .appendSlice (gpa , line_bytes );
tok_i += 1 ;
}
while (tok_i <= end ) : (tok_i += 1 ) {
const slice = tree .tokenSlice (tok_i );
const line_bytes = slice [2 ..];
try string_bytes .ensureUnusedCapacity (gpa , line_bytes .len + 1 );
string_bytes .appendAssumeCapacity ('\n' );
string_bytes .appendSliceAssumeCapacity (line_bytes );
}
const len = string_bytes .items .len - str_index ;
try string_bytes .append (gpa , 0 );
return IndexSlice {
.index = @fromBackingInt (@intCast (str_index )),
.len = @intCast (len ),
};
}