textfile

package module
v0.0.0-...-dc50546 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2016 License: MIT Imports: 9 Imported by: 1

README

textfile

GO utility functions for textfile parsing

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Lines    []Line   // logical lines
	Warnings []string // warnings or errors encounted during the last parse

	JoinLines bool // if set to true, lines ending in \ will be joined
	Includes  bool // if set to true, files can include others
}

File contains the logical lines read from text files, errors that were encountered and options to control parsing.

func Load

func Load(file string) (*File, error)

Load returns a File structure containing the parsed contents of the given file.

func Parse

func Parse(text string, file string) *File

Parse returns a File structure containing the parsed contents of the given text.

func (*File) Load

func (f *File) Load(file string) error

Load reads and parses the given file into the File structure.

func (*File) Parse

func (f *File) Parse(text string, file string)

Parse parses the given text into the File structure.

type Line

type Line struct {
	Text   string
	Source LineSource
}

Line contains content and meta info of one logical line of text

func JoinLines

func JoinLines(lines *[]Line) (joined []Line)

JoinLines joins consecutive lines ending with the continuing character \ into a logical line. Leading whitespace will be stripped on continuing lines.

func LoadFile

func LoadFile(file string, options map[string]interface{}) ([]Line, []string, error)

LoadFile parses the given file according to the rules specified in the options and returns a slice of Line, an error if the file could not be read and a slice of strings containing any other warnings or errors encountered during parsing.

func ParseText

func ParseText(text string, file string, options map[string]interface{}) (result []Line, warnings []string)

ParseText parses the given text according to the rules specified in the options and returns a slice of Line and a slice of strings containing any errors or warnings encountered during parsing.

func ReadLines

func ReadLines(file string) ([]Line, error)

ReadLines reads all physical lines from the given file and returns a slice of Line structures.

func (*Line) Origin

func (l *Line) Origin() string

Origin returns the line's origin as a string (equivalent to line.Source.Text())

type LineSource

type LineSource struct {
	File       string
	LineNumber int
	Count      int
}

LineSource contains the source file, line number and number of physical lines making up a logical line.

func (*LineSource) Text

func (s *LineSource) Text() string

Text returns a string representation of the LineSource.

Jump to

Keyboard shortcuts

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