structstd.json.scanner.Diagnostics[src]

To enable diagnostics, declare var diagnostics = Diagnostics{}; then call source.enableDiagnostics(&diagnostics); where source is either a std.json.Reader or a std.json.Scanner that has just been initialized. At any time, notably just after an error, call getLine(), getColumn(), and/or getByteOffset() to get meaningful information from this.

Fields

line_number: u64 = 1
line_start_cursor: usize = @as(usize, @bitCast(@as(isize, -1)))
total_bytes_before_current_input: u64 = 0
cursor_pointer: *const usize = undefined

Functions

FunctiongetLine[src]

pub fn getLine(self: *const @This()) u64

Starts at 1.

Parameters

self: *const @This()

Source Code

Source code
pub fn getLine(self: *const @This()) u64 {
    return self.line_number;
}

FunctiongetColumn[src]

pub fn getColumn(self: *const @This()) u64

Starts at 1.

Parameters

self: *const @This()

Source Code

Source code
pub fn getColumn(self: *const @This()) u64 {
    return self.cursor_pointer.* -% self.line_start_cursor;
}

FunctiongetByteOffset[src]

pub fn getByteOffset(self: *const @This()) u64

Starts at 0. Measures the byte offset since the start of the input.

Parameters

self: *const @This()

Source Code

Source code
pub fn getByteOffset(self: *const @This()) u64 {
    return self.total_bytes_before_current_input + self.cursor_pointer.*;
}

Source Code

Source code
pub const Diagnostics = struct {
    line_number: u64 = 1,
    line_start_cursor: usize = @as(usize, @bitCast(@as(isize, -1))), // Start just "before" the input buffer to get a 1-based column for line 1.
    total_bytes_before_current_input: u64 = 0,
    cursor_pointer: *const usize = undefined,

    /// Starts at 1.
    pub fn getLine(self: *const @This()) u64 {
        return self.line_number;
    }
    /// Starts at 1.
    pub fn getColumn(self: *const @This()) u64 {
        return self.cursor_pointer.* -% self.line_start_cursor;
    }
    /// Starts at 0. Measures the byte offset since the start of the input.
    pub fn getByteOffset(self: *const @This()) u64 {
        return self.total_bytes_before_current_input + self.cursor_pointer.*;
    }
}