DoxigAlpha

parseAlloc

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

Function parameters

Parameters

#
allocator:std.mem.Allocator
bytes:[]const u8

Type definitions in this namespace

Types

#

Asserts the slice starts and ends with single-quotes.

Functions

#
parseCharLiteral
Asserts the slice starts and ends with single-quotes.
parseEscapeSequence
Parse an escape sequence from `slice[offset..]`.
parseWrite
Parses `bytes` as a Zig string literal and writes the result to the `Writer` type.
parseAlloc
Higher level API.

Error sets in this namespace

Error Sets

#

Source

Implementation

#
pub fn parseAlloc(allocator: std.mem.Allocator, bytes: []const u8) ParseError![]u8 {
    var aw: std.io.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,
    }
}