sourcecode

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDecDigitExpected = errors.New("a valid decimal digit expected")
View Source
var ErrHexDigitExpected = errors.New("a valid hex digit expected")

Functions

func JsonErrorOffset64

func JsonErrorOffset64(err error) int64

func LineContentAt

func LineContentAt[T StringLikeContent](buf T, anchor Anchor) T

func MakeJsonFileLocationError

func MakeJsonFileLocationError(filename string, buf []byte, err error) error

func MakeJsonLocationError

func MakeJsonLocationError(buf []byte, err error) error

Types

type Anchor

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

func CalcAnchor

func CalcAnchor[T StringLikeContent](buf T) Anchor

func (*Anchor) LineNumber

func (a *Anchor) LineNumber() int

func (*Anchor) Offset

func (a *Anchor) Offset() int

type FileLocation

type FileLocation struct {
	Filename string
	Location
}

func (*FileLocation) String

func (loc *FileLocation) String() string

type FileLocationError

type FileLocationError struct {
	Filename string
	Location Location
	Err      error
}

func NewFileLocationError

func NewFileLocationError(fl FileLocation, err error) *FileLocationError

func (*FileLocationError) Error

func (e *FileLocationError) Error() string

type Location

type Location struct {
	LineNumber   int // 1-based
	ColumnNumber int // 1-based
}

Location specifies line:column position within a text file

  • both numers are 1-indexed
  • zero values are used when line or column is unknown

note: that the column number here may differ from what your text editor is showing, due to the following simplifications:

  • we can't expand tabs `\t` because we don't have a clue what's the tab size is
  • we can't account for zero-width and wide (double-column) characters because unicode character width lookup is outside of the scope of this library

func LocationAt

func LocationAt[T StringLikeContent](buf T, anchor Anchor) Location

func (*Location) String

func (loc *Location) String() string

func (*Location) Valid

func (loc *Location) Valid() bool

type LocationError

type LocationError struct {
	Location Location
	Err      error
}

func NewLocationError

func NewLocationError(loc Location, err error) *LocationError

func (*LocationError) Error

func (e *LocationError) Error() string

type Scanner

type Scanner struct {
	Filepath string
	// contains filtered or unexported fields
}

Scanner is a generic helper for scraping source code for translation strings

func NewFileScanner

func NewFileScanner(filepath string) (*Scanner, error)

func NewScanner

func NewScanner[T StringLikeContent](b T) *Scanner

func (*Scanner) Anchor

func (scn *Scanner) Anchor() Anchor

func (*Scanner) IsAnyOf

func (scn *Scanner) IsAnyOf(chars string) bool

func (*Scanner) IsByte

func (scn *Scanner) IsByte(c byte) bool

func (*Scanner) IsByteFunc

func (scn *Scanner) IsByteFunc(f func(byte) bool) bool

func (*Scanner) IsEOF

func (scn *Scanner) IsEOF() bool

func (*Scanner) IsEOL

func (scn *Scanner) IsEOL() bool

func (*Scanner) IsNextByte

func (scn *Scanner) IsNextByte(offset int, c byte) bool

func (*Scanner) IsNextByteFunc

func (scn *Scanner) IsNextByteFunc(offset int, f func(byte) bool) bool

func (*Scanner) IsSequence

func (scn *Scanner) IsSequence(s string) bool

func (*Scanner) IsWS

func (scn *Scanner) IsWS() bool

func (*Scanner) LineContentAt

func (scn *Scanner) LineContentAt(anchor Anchor) string

func (*Scanner) LocationAt

func (scn *Scanner) LocationAt(anchor Anchor) Location

func (*Scanner) MakeErrorAt

func (scn *Scanner) MakeErrorAt(anchor Anchor, err error) error

func (*Scanner) ReadDecUint

func (scn *Scanner) ReadDecUint() (uint64, error)

func (*Scanner) ReadHexUint

func (scn *Scanner) ReadHexUint() (uint64, error)

func (*Scanner) ReadLineUntil

func (scn *Scanner) ReadLineUntil(c byte) string

func (*Scanner) ReadSequenceFunc

func (scn *Scanner) ReadSequenceFunc(isFirst, isOther func(byte) bool) string

func (*Scanner) Skip

func (scn *Scanner) Skip() bool

func (*Scanner) SkipByte

func (scn *Scanner) SkipByte(c byte) bool

func (*Scanner) SkipByteFunc

func (scn *Scanner) SkipByteFunc(f func(byte) bool) bool

func (*Scanner) SkipEOL

func (scn *Scanner) SkipEOL() bool

func (*Scanner) SkipSequence

func (scn *Scanner) SkipSequence(s string) bool

func (*Scanner) SkipWS

func (scn *Scanner) SkipWS() bool

func (*Scanner) SkipWSEOL

func (scn *Scanner) SkipWSEOL() bool

type StringLikeContent

type StringLikeContent interface {
	~string | []byte
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL