streampos: github.com/phf/streampos Index | Files | Directories

package streampos

import "github.com/phf/streampos"

Package streampos exports a Writer that tracks (line, column) positions suitable for error messages.

Index

Package Files

streampos.go

type Writer Uses

type Writer struct {
    // contains filtered or unexported fields
}

Writer looks for newline characters and constructs a mapping from byte offset ranges to line numbers. It is typically used with a TeeReader to track positions in some input stream.

func (*Writer) Column Uses

func (w *Writer) Column(offset int64) (int64, error)

Column returns the column number for the given offset. See Position for more information.

func (*Writer) Length Uses

func (w *Writer) Length() int64

Length returns how many bytes have been processed so far.

func (*Writer) Line Uses

func (w *Writer) Line(offset int64) (int64, error)

Line returns the line number for the given offset. See Position for more information.

func (*Writer) Position Uses

func (w *Writer) Position(offset int64) (line, column int64, err error)

Position returns the line and column number for the given offset in the underlying data stream. The offset cannot be negative but must be less than Length. Line numbers start at 1 from the beginning of the stream, column numbers start at 1 from the beginning of the line (left to right). Note that column numbers are based on bytes, so '\t' counts as 1 column whereas multi-byte runes count as several.

func (*Writer) Write Uses

func (w *Writer) Write(b []byte) (n int, err error)

Write accepts data to track positions in. It does not perform any actual I/O, so writes are never short (and never fail).

Directories

PathSynopsis
example

Package streampos imports 1 packages (graph) and is imported by 1 packages. Updated 2016-07-17. Refresh now. Tools for package owners.