tool

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: MIT Imports: 17 Imported by: 12

Documentation

Index

Constants

View Source
const StringMetricFactor = 100000000000

StringMetricFactor for JaroWinklerDistance algorithm

Variables

View Source
var SavedOsArgs []string

SavedOsArgs is a copy of os.Args, just for testing

Functions

func EraseAnyWSs

func EraseAnyWSs(s string) string

EraseAnyWSs eats any whitespaces inside the giving string s.

func GetTtySize added in v1.7.9

func GetTtySize() (cols, rows int)

GetTtySize returns the window size in columns and rows in the active console window. The return value of this function is in the order of cols, rows.

func HasOrderPrefix

func HasOrderPrefix(s string) bool

HasOrderPrefix tests whether an order prefix is present or not. An order prefix is a dotted string with multiple alphabet and digit. Such as: "zzzz.", "0001.", "700.", "A1." ...

func IsDigitHeavy

func IsDigitHeavy(s string) bool

IsDigitHeavy tests if the whole string is digit

func Launch

func Launch(cmd string, args ...string) (err error)

Launch executes a command setting both standard input, output and error.

func LaunchEditor

func LaunchEditor(editor string) (content []byte, err error)

LaunchEditor launches the specified editor

func LaunchEditorWith

func LaunchEditorWith(editor string, filename string) (content []byte, err error)

LaunchEditorWith launches the specified editor with a filename

func Max

func Max(a, b int) int

Max return the larger one of int

func Min

func Min(a, b int) int

Min return the less one of int

func ParseComplex

func ParseComplex(s string) (v complex128)

ParseComplex converts a string to complex number.

Examples:

c1 := cmdr.ParseComplex("3-4i")
c2 := cmdr.ParseComplex("3.13+4.79i")

func ParseComplexX

func ParseComplexX(s string) (v complex128, err error)

ParseComplexX converts a string to complex number. If the string is not valid complex format, return err not nil.

Examples:

c1 := cmdr.ParseComplex("3-4i")
c2 := cmdr.ParseComplex("3.13+4.79i")

func PressAnyKeyToContinue

func PressAnyKeyToContinue(in io.Reader, msg ...string) (input string)

PressAnyKeyToContinue lets program pause and wait for user's ANY key press in console/terminal

func PressEnterToContinue

func PressEnterToContinue(in io.Reader, msg ...string) (input string)

PressEnterToContinue lets program pause and wait for user's ENTER key press in console/terminal

func RandomStringPure

func RandomStringPure(length int) (result string)

RandomStringPure generate a random string with length specified.

func ReadPassword

func ReadPassword() (text string, err error)

ReadPassword reads the password from stdin with safe protection

func SortAsDottedSlice added in v1.7.25

func SortAsDottedSlice(ks []string)

SortAsDottedSlice sorts a slice by which is treated as a dot-separated path string

func SortAsDottedSliceReverse added in v1.7.25

func SortAsDottedSliceReverse(ks []string)

SortAsDottedSliceReverse sorts a slice by which is treated as a dot-separated path string

func Soundex

func Soundex(s string) (snd4 string)

Soundex returns the english word's soundex value, such as: 'tags' => 't322'

func StripOrderPrefix

func StripOrderPrefix(s string) string

StripOrderPrefix strips the prefix string fragment for sorting order. see also: Command.Group, Flag.Group, ... An order prefix is a dotted string with multiple alphabet and digit. Such as: "zzzz.", "0001.", "700.", "A1." ...

func StripPrefix

func StripPrefix(s, p string) string

StripPrefix strips the prefix 'p' from a string 's'

func StripQuotes

func StripQuotes(s string) string

StripQuotes strips single or double quotes around a string.

Types

type DistanceOption

type DistanceOption func(StringDistance)

DistanceOption is a functional options prototype

func JWWithThreshold

func JWWithThreshold(threshold float64) DistanceOption

JWWithThreshold sets the threshold for Jaro-Winkler algorithm.

type StringDistance

type StringDistance interface {
	Calc(s1, s2 string, opts ...DistanceOption) (distance int)
}

StringDistance is an interface for string metric. A string metric is a metric that measures distance between two strings. In most case, it means that the edit distance about those two strings. This is saying, it is how many times are needed while you were modifying string to another one, note that inserting, deleting, substing one character means once.

func JaroWinklerDistance

func JaroWinklerDistance(opts ...DistanceOption) StringDistance

JaroWinklerDistance returns an calculator for two strings distance metric, with Jaro-Winkler algorithm.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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