Documentation ¶
Overview ¶
Package stringutil contains common function for string operations.
Index ¶
- Variables
- func CamelCaseSplit(src string) []string
- func ChunkSplit(s string, size int, spaceSplit bool) []string
- func ConvertToJSONMarshalableObject(v interface{}) interface{}
- func ConvertToPrettyString(v interface{}) string
- func ConvertToString(v interface{}) string
- func CreateDisplayString(str string) string
- func GenerateRollingString(seq string, size int) string
- func GlobStartingLiterals(glob string) string
- func GlobToRegex(glob string) (string, error)
- func IndexOf(str string, slice []string) int
- func IsAlphaNumeric(str string) bool
- func IsTrueValue(str string) bool
- func LengthConstantEquals(str1 []byte, str2 []byte) bool
- func LevenshteinDistance(str1, str2 string) int
- func LongestCommonPrefix(s []string) string
- func MD5HexString(str string) string
- func MapKeys(m map[string]interface{}) []string
- func Plural(l int) string
- func PrintCSVTable(ss []string, c int) string
- func PrintGraphicStringTable(ss []string, c int, n int, syms *GraphicStringTableSymbols) string
- func PrintStringTable(ss []string, c int) string
- func ProperTitle(input string) string
- func QuoteCLIArgs(args []string) string
- func RuneSliceToString(buf []rune) string
- func StringToRuneSlice(s string) []rune
- func StripCStyleComments(text []byte) []byte
- func StripUniformIndentation(s string) string
- func ToUnixNewlines(s string) string
- func TrimBlankLines(s string) string
- func VersionStringCompare(str1, str2 string) int
- type GlobParseError
- type GraphicStringTableSymbols
Constants ¶
This section is empty.
Variables ¶
var ( SingleLineTable = &GraphicStringTableSymbols{"─", "│", "┼", "┌", "┐", "└", "┘", "┬", "├", "┤", "┴"} DoubleLineTable = &GraphicStringTableSymbols{"═", "║", "╬", "╔", "╗", "╚", "╝", "╦", "╠", "╣", "╩"} SingleDoubleLineTable = &GraphicStringTableSymbols{"═", "│", "╪", "╒", "╕", "╘", "╛", "╤", "╞", "╡", "╧"} DoubleSingleLineTable = &GraphicStringTableSymbols{"─", "║", "╫", "╓", "╖", "╙", "╜", "╥", "╟", "╢", "╨"} MonoTable = &GraphicStringTableSymbols{"#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#"} )
Standard graphic table drawing definitions.
Functions ¶
func CamelCaseSplit ¶
CamelCaseSplit splits a camel case string into a slice.
func ChunkSplit ¶
ChunkSplit splits a string into chunks of a defined size. Attempts to only split at white space characters if spaceSplit is set.
func ConvertToJSONMarshalableObject ¶
func ConvertToJSONMarshalableObject(v interface{}) interface{}
ConvertToJSONMarshalableObject converts container contents into objects which can be converted into JSON strings.
func ConvertToPrettyString ¶
func ConvertToPrettyString(v interface{}) string
ConvertToPrettyString tries to convert a given object into a stable human-readable string.
func ConvertToString ¶
func ConvertToString(v interface{}) string
ConvertToString tries to convert a given object into a stable string. This function can be used to display nested maps.
func CreateDisplayString ¶
CreateDisplayString changes all "_" characters into spaces and properly capitalizes the resulting string.
func GenerateRollingString ¶
GenerateRollingString creates a string by repeating a given string pattern.
func GlobStartingLiterals ¶
GlobStartingLiterals gets the first literals of a glob string.
func GlobToRegex ¶
GlobToRegex converts a given glob expression into a regular expression.
func IsAlphaNumeric ¶
IsAlphaNumeric checks if a string contains only alpha numerical characters or "_".
func IsTrueValue ¶
IsTrueValue checks if a given string is a true value.
func LengthConstantEquals ¶
LengthConstantEquals compares two strings in length-constant time. This function is deliberately inefficient in that it does not stop at the earliest possible time. This is to prevent timing attacks when comparing password hashes.
func LevenshteinDistance ¶
LevenshteinDistance computes the Levenshtein distance between two strings.
func LongestCommonPrefix ¶
LongestCommonPrefix determines the longest common prefix of a given list of strings.
func MD5HexString ¶
MD5HexString calculates the MD5 sum of a string and returns it as hex string.
func Plural ¶
Plural returns the string 's' if the parameter is greater than one or if the parameter is 0.
func PrintCSVTable ¶
PrintCSVTable prints a given list of strings in a CSV table with c columns.
func PrintGraphicStringTable ¶
func PrintGraphicStringTable(ss []string, c int, n int, syms *GraphicStringTableSymbols) string
PrintGraphicStringTable prints a given list of strings in a graphic table with c columns - creates a header after n rows using syms as drawing symbols.
func PrintStringTable ¶
PrintStringTable prints a given list of strings as table with c columns.
func ProperTitle ¶
ProperTitle will properly capitalize a title string by capitalizing the first, last and any important words. Not capitalized are articles: a, an, the; coordinating conjunctions: and, but, or, for, nor; prepositions (fewer than five letters): on, at, to, from, by.
func QuoteCLIArgs ¶ added in v1.4.6
func RuneSliceToString ¶
RuneSliceToString converts a slice of runes into a string.
func StringToRuneSlice ¶
StringToRuneSlice converts a string into a slice of runes.
func StripCStyleComments ¶
StripCStyleComments strips out C-Style comments from a given string.
func StripUniformIndentation ¶
StripUniformIndentation removes uniform indentation from a string.
func ToUnixNewlines ¶
ToUnixNewlines converts all newlines in a given string to unix newlines.
func TrimBlankLines ¶
TrimBlankLines removes blank initial and trailing lines.
func VersionStringCompare ¶
VersionStringCompare compares two version strings. Returns: 0 if the strings are equal; -1 if the first string is smaller; 1 if the first string is greater.
Types ¶
type GlobParseError ¶
GlobParseError describes a failure to parse a glob expression and gives the offending expression.
func (*GlobParseError) Error ¶
func (e *GlobParseError) Error() string
Error Returns a string representation of the error.
type GraphicStringTableSymbols ¶
type GraphicStringTableSymbols struct { BoxHorizontal string BoxVertical string BoxMiddle string BoxCornerTopLeft string BoxCornerTopRight string BoxCornerBottomLeft string BoxCornerBottomRight string BoxTopMiddle string BoxLeftMiddle string BoxRightMiddle string BoxBottomMiddle string }
GraphicStringTableSymbols defines how to draw a graphic table.