~ntgg/zosh

00d69d48b471db02551373ba32e944cbc8c73a2d — Noah Graff 4 years ago 762f8c5
document and better support of text ranges
1 files changed, 10 insertions(+), 0 deletions(-)

M src/text_buffer.zig
M src/text_buffer.zig => src/text_buffer.zig +10 -0
@@ 7,7 7,9 @@ pub const TextBuffer = struct {
    allocator: *Allocator,

    pub const Range = struct {
        /// start of range, inclusive.
        start: Pos,
        /// end of range, exclusive.
        end: Pos,
    };



@@ 56,6 58,14 @@ pub const TextBuffer = struct {
        return buf.bytes[buf.pos.offset + idx];
    }

    pub fn atPos(buf: TextBuffer, pos: Pos) u8 {
        return buf.bytes[pos.offset];
    }

    pub fn sliceRange(buf: TextBuffer, range: Range) []const u8 {
        return buf.bytes[range.start.offset..range.end.offset - 1];
    }

    // Invalidates all slices into the TextBuffer.
    pub fn append(buf: *TextBuffer, text: []const u8) !void {
        const old_end = buf.bytes.len;