util

package
v0.0.0-...-5da5f19 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2016 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package util contains utility functions.

Index

Constants

View Source
const (
	MaxUint = ^uint(0)
	MinUint = 0
	MaxInt  = int(MaxUint >> 1)
	MinInt  = -MaxInt - 1
)

Variables

View Source
var (
	ErrNotExecutable = errors.New("not executable")
	ErrNotFound      = errors.New("not found")
)
View Source
var ErrIndexOutOfRange = errors.New("substring out of range")

ErrIndexOutOfRange is returned when out-of-range errors occur.

Functions

func AllExecutables

func AllExecutables(paths []string, names chan<- string)

AllExecutables writes the names of all executable files in the search path to a channel.

func CatError

func CatError(err error, more error) error

func Catch

func Catch(perr *error)

Catch tries to catch an error thrown by Throw and stop the panic. If the panic is not caused by Throw, the panic is not stopped.

func CeilDiv

func CeilDiv(a, b int) int

CeilDiv computes ceil(float(a)/b) without using float arithmetics.

func DeepPrint

func DeepPrint(x interface{}) string

DeepPrint is like printing with the %#v formatter of fmt, but it prints pointer fields recursively.

func DontSearch

func DontSearch(exe string) bool

DontSearch determines whether the path to an external command should be taken literally and not searched.

func FindContext

func FindContext(text string, pos int) (lineno, colno int, line string)

FindContext takes a position in a text and finds its line number, corresponding line and column numbers. Line and column numbers are counted from 0. Used in diagnostic messages.

func FindFirstEOL

func FindFirstEOL(s string) int

FindFirstEOL returns the index of the first '\n'. When there is no '\n', the length of s is returned.

func FindLastSOL

func FindLastSOL(s string) int

FindLastSOL returns an index just after the last '\n'.

func GetHome

func GetHome(uname string) (string, error)

GetHome finds the home directory of a specified user. When given an empty string, it finds the home directory of the current user.

func GetLogger

func GetLogger(prefix string) *log.Logger

GetLogger gets a logger with a prefix.

func Getwd

func Getwd() string

Getwd returns path of the working directory in a format suitable as the prompt.

func IsExecutable

func IsExecutable(path string) bool

IsExecutable determines whether path refers to an executable file.

func MatchSubseq

func MatchSubseq(s, pattern string) bool

MatchSubseq returns whether pattern is a subsequence of s.

func NthRune

func NthRune(s string, n int) (rune, error)

NthRune returns the n-th rune of s.

func RootStar

func RootStar() []string

RootNames returns the result of /*.

func Search(paths []string, exe string) (string, error)

Search tries to resolve an external command and return the full (possibly relative) path.

func SetOutputFile

func SetOutputFile(fname string) error

func SubstringByRune

func SubstringByRune(s string, low, high int) (string, error)

SubstringByRune returns the range of the i-th rune (inclusive) through the j-th rune (exclusive) in s.

func Throw

func Throw(err error)

Throw panics with err wrapped properly so that it can be catched by Catch.

func TildeAbbr

func TildeAbbr(path string) string

TildeAbbr abbreviates the user's home directory to ~.

Types

type Errors

type Errors struct {
	Errors []error
}

Errors pack multiple errors into one error.

func (*Errors) Append

func (es *Errors) Append(e error)

func (*Errors) Error

func (es *Errors) Error() string

type Exception

type Exception struct {
	Error error
}

type marker for exceptions

type PosError

type PosError struct {
	Begin int
	End   int
	Err   error
}

PosError is an error associated with a position range.

func (*PosError) Error

func (pe *PosError) Error() string

func (*PosError) Pprint

func (pe *PosError) Pprint(srcname, errtype, src string) string

Pprint pretty-prints a PosError with a header indicating the source and type of the error, the error text and the affected line with an additional line that points an arrow at the affected column.

Jump to

Keyboard shortcuts

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