util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsString

func AsString(x interface{}) string

AsString returns the argument in a 'string' form no matter what type it is.

func AutoIndexColumnID

func AutoIndexColumnID(colIdx int) string

AutoIndexColumnID returns a unique Column ID/Name for the given Column Index. The functionality is similar to what you get in an Excel spreadsheet w.r.t. the Column ID/Name.

func FilterStrings

func FilterStrings(s []string, f func(string) bool) []string

FilterStrings filters the slice 's' to items which return truth when passed to 'f'.

func GetLongestLineLength

func GetLongestLineLength(s string) int

GetLongestLineLength returns the length of the longest "line" within the argument string. For ex.:

GetLongestLineLength("Ghost!\nCome back here!\nRight now!") == 15

func InsertRuneEveryN

func InsertRuneEveryN(s string, c rune, n int) string

InsertRuneEveryN inserts the rune every N characters in the string. For ex.:

InsertRuneEveryN("Ghost", '-', 1) == "G-h-o-s-t"
InsertRuneEveryN("Ghost", '-', 2) == "Gh-os-t"
InsertRuneEveryN("Ghost", '-', 3) == "Gho-st"
InsertRuneEveryN("Ghost", '-', 4) == "Ghos-t"
InsertRuneEveryN("Ghost", '-', 5) == "Ghost"

func IsNumber

func IsNumber(x interface{}) bool

IsNumber returns true if the argument is a numeric type; false otherwise.

func IsString

func IsString(x interface{}) bool

IsString returns true if the argument is a string; false otherwise.

func RuneCountWithoutEscapeSeq

func RuneCountWithoutEscapeSeq(s string) int

RuneCountWithoutEscapeSeq is similar to utf8.RuneCountInString, except for the fact that it ignores escape sequences in the counting. For ex.:

RuneCountWithoutEscapeSeq("") == 0
RuneCountWithoutEscapeSeq("Ghost") == 5
RuneCountWithoutEscapeSeq("\x1b[33mGhost\x1b[0m") == 5
RuneCountWithoutEscapeSeq("\x1b[33mGhost\x1b[0") == 5

func TrimTextWithoutEscapeSeq

func TrimTextWithoutEscapeSeq(s string, n int) string

TrimTextWithoutEscapeSeq trims a string to the given length accounting for escape sequences For ex.:

TrimTextWithoutEscapeSeq("Ghost", 3) == "Gho"
TrimTextWithoutEscapeSeq("Ghost", 6) == "Ghost"
TrimTextWithoutEscapeSeq("\x1b[33mGhost\x1b[0m", 3) == "\x1b[33mGho\x1b[0m"
TrimTextWithoutEscapeSeq("\x1b[33mGhost\x1b[0m", 6) == "\x1b[33mGhost\x1b[0m"

func WrapText

func WrapText(s string, n int) string

WrapText wraps a string to the given length using a newline. For ex.:

WrapText("Ghost", 1) == "G\nh\no\ns\nt"
WrapText("Ghost", 2) == "Gh\nos\nt"
WrapText("Ghost", 3) == "Gho\nst"
WrapText("Ghost", 4) == "Ghos\nt"
WrapText("Ghost", 5) == "Ghost"
WrapText("Ghost", 6) == "Ghost"
WrapText("Jon\nSnow", 2) == "Jo\nn\nSn\now"
WrapText("Jon\nSnow\n", 2) == "Jo\nn\nSn\now\n"

Types

This section is empty.

Jump to

Keyboard shortcuts

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