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.

transStringLiteral

Translator.transStringLiteral
fn transStringLiteral(
    t: *Translator,
    scope: *Scope,
    expr: Node.Index,
    literal: Node.CharLiteral,
) TransError!ZigNode

File

lib/compiler/translate-c/Translator.zig:3603

Code

fn transStringLiteral(
    t: *Translator,
    scope: *Scope,
    expr: Node.Index,
    literal: Node.CharLiteral,
) TransError!ZigNode {
    switch (literal.kind) {
        .ascii, .utf8 => return t.transNarrowStringLiteral(expr, literal),
        .utf16, .utf32, .wide => {
            const name = try std.fmt.allocPrint(t.arena, "{s}_string_{d}", .{ @tagName(literal.kind), t.getMangle() });

            const array_type = try t.transTypeInit(scope, literal.qt, expr, literal.literal_tok);
            const lit_array = try t.transStringLiteralInitializer(expr, literal, array_type);
            const decl = try ZigTag.var_simple.create(t.arena, .{ .name = name, .init = lit_array });
            try scope.appendNode(decl);
            return ZigTag.identifier.create(t.arena, name);
        },
    }
}