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.

parseAlloc

Higher level API. Does not return extra info about parse errors. Caller owns returned memory.

string_literal.parseAlloc
pub fn parseAlloc(allocator: std.mem.Allocator, bytes: []const u8) ParseError![]u8

File

lib/std/zig/string_literal.zig:360

Code

pub fn parseAlloc(allocator: std.mem.Allocator, bytes: []const u8) ParseError![]u8 {
    var aw: Writer.Allocating = .init(allocator);
    defer aw.deinit();
    const result = parseWrite(&aw.writer, bytes) catch |err| switch (err) {
        error.WriteFailed => return error.OutOfMemory,
    };
    switch (result) {
        .success => return aw.toOwnedSlice(),
        .failure => return error.InvalidLiteral,
    }
}