Documentation ¶
Overview ¶
Package util contains utility functions.
Index ¶
- Constants
- Variables
- func CatError(err error, more error) error
- func Catch(perr *error)
- func CeilDiv(a, b int) int
- func DeepPrint(x interface{}) string
- func DoesntThrow(f func()) bool
- func DontSearch(exe string) bool
- func EachExecutable(paths []string, f func(string))
- func FindContext(text string, pos int) (lineno, colno int, line string)
- func FindFirstEOL(s string) int
- func FindLastSOL(s string) int
- func ForceWcwidth(s string, width int) string
- func FullNames(dir string) []string
- func GetHome(uname string) (string, error)
- func GetLogger(prefix string) *log.Logger
- func Getwd() string
- func HasSubseq(s, t string) bool
- func InTempDir(f func(string))
- func IsExecutable(path string) bool
- func MatchSubseq(s, pattern string) bool
- func NthRune(s string, n int) (rune, error)
- func OverrideWcwidth(r rune, w int)
- func PCall(f func()) (e error)
- func Search(paths []string, exe string) (string, error)
- func SetOutputFile(fname string) error
- func SubstringByRune(s string, low, high int) (string, error)
- func Throw(err error)
- func Throws(f func(), e error) bool
- func TildeAbbr(path string) string
- func TrimEachLineWcwidth(s string, width int) string
- func TrimWcwidth(s string, wmax int) string
- func UnoverrideWcwidth(r rune)
- func Wcswidth(s string) (w int)
- func Wcwidth(r rune) int
- type Errors
- type Pprinter
- type SourceContext
- type Thrown
Constants ¶
const ( MaxUint = ^uint(0) MinUint = 0 MaxInt = int(MaxUint >> 1) MinInt = -MaxInt - 1 )
Variables ¶
var ( ErrNotExecutable = errors.New("not executable") ErrNotFound = errors.New("not found") )
var CulpritStyle = "1;4"
var ErrIndexOutOfRange = errors.New("substring out of range")
ErrIndexOutOfRange is returned when out-of-range errors occur.
Functions ¶
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. It should be called directly from defer.
func DeepPrint ¶
func DeepPrint(x interface{}) string
DeepPrint is like printing with the %#v formatter of fmt, but it prints pointer fields recursively.
func DoesntThrow ¶
func DoesntThrow(f func()) bool
DoesntThrow returns whether calling f does not throw anything. It is useful for testing.
func DontSearch ¶
DontSearch determines whether the path to an external command should be taken literally and not searched.
func EachExecutable ¶
EachExecutable calls f for each executable file in paths.
func FindContext ¶
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 ¶
FindFirstEOL returns the index of the first '\n'. When there is no '\n', the length of s is returned.
func FindLastSOL ¶
FindLastSOL returns an index just after the last '\n'.
func ForceWcwidth ¶
ForceWcwidth forces the string s to the given display width by trimming and padding.
func FullNames ¶
FullNames returns the full names of non-hidden files under a directory. The directory name should end in a slash. If the directory cannot be listed, it returns nil.
The output should be the same as globbing dir + "*". It is used for testing globbing.
func GetHome ¶
GetHome finds the home directory of a specified user. When given an empty string, it finds the home directory of the current user.
func Getwd ¶
func Getwd() string
Getwd returns path of the working directory in a format suitable as the prompt.
func InTempDir ¶
func InTempDir(f func(string))
InTempDir creates a new temporary directory, cd into it, and runs a function, passing the path of the temporary directory. After the function returns, it goes back to the original directory if possible, and remove the temporary directory. It panics if it cannot make a temporary directory or cd into it.
It is useful in tests.
func IsExecutable ¶
IsExecutable determines whether path refers to an executable file.
func MatchSubseq ¶
MatchSubseq returns whether pattern is a subsequence of s.
func OverrideWcwidth ¶
OverrideWcwidth overrides the wcwidth of a rune to be a specific non-negative value. OverrideWcwidth panics if w < 0.
func PCall ¶
func PCall(f func()) (e error)
PCall calls a function and catches anything Thrown'n and returns it. It does not protect against panics not using Throw, nor can it distinguish between nothing thrown and Throw(nil).
func Search ¶
Search tries to resolve an external command and return the full (possibly relative) path.
func SetOutputFile ¶
func SubstringByRune ¶
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 Throws ¶
Throws returns whether calling f throws out a certain error (using Throw). It is useful for testing.
func TrimEachLineWcwidth ¶
func TrimWcwidth ¶
TrimWcwidth trims the string s so that it has a width of at most wmax.
func UnoverrideWcwidth ¶
func UnoverrideWcwidth(r rune)
UnoverrideWcwidth removes the override of a rune.
Types ¶
type SourceContext ¶
type SourceContext struct { Name string Source string Begin int End int Next *SourceContext }