findLineColumn
Function parameters
Parameters
- source:[]const u8
- byte_offset:usize
Type definitions in this namespace
Types
- EnvVar
- Collects all the environment variables that Zig could possibly inspect, so
- EmitArtifact
- Every kind of artifact which the compiler can emit.
Functions in this namespace
Functions
- binNameAlloc
- Returns the standard file system basename of a binary generated by the Zig compiler.
- serializeCpu
- Renders a `std.Target.Cpu` value into a textual representation that can be parsed
- fmtId
- Return a Formatter for a Zig identifier, escaping it with `@""` syntax if needed.
- fmtIdFlags
- Return a Formatter for a Zig identifier, escaping it with `@""` syntax if needed.
- fmtString
- Return a formatter for escaping a double quoted Zig string.
- fmtChar
- Return a formatter for escaping a single quoted Zig string.
- stringEscape
- Print the string as escaped contents of a double quoted string.
- charEscape
- Print as escaped contents of a single-quoted string.
- readSourceFileToEndAlloc
- If the source can be UTF-16LE encoded, this function asserts that `gpa`
There are many assumptions in the entire codebase that Zig source files can
Values
- max_src_size
- There are many assumptions in the entire codebase that Zig source files can
Source
Implementation
pub fn findLineColumn(source: []const u8, byte_offset: usize) Loc {
var line: usize = 0;
var column: usize = 0;
var line_start: usize = 0;
var i: usize = 0;
while (i < byte_offset) : (i += 1) {
switch (source[i]) {
'\n' => {
line += 1;
column = 0;
line_start = i + 1;
},
else => {
column += 1;
},
}
}
while (i < source.len and source[i] != '\n') {
i += 1;
}
return .{
.line = line,
.column = column,
.source_line = source[line_start..i],
};
}