stringutil

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: CC0-1.0 Imports: 13 Imported by: 26

Documentation

Overview

Package stringutil contains common function for string operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	SingleLineTable       = &GraphicStringTableSymbols{"─", "│", "┼", "┌", "┐", "└", "┘", "┬", "├", "┤", "┴"}
	DoubleLineTable       = &GraphicStringTableSymbols{"═", "║", "╬", "╔", "╗", "╚", "╝", "╦", "╠", "╣", "╩"}
	SingleDoubleLineTable = &GraphicStringTableSymbols{"═", "│", "╪", "╒", "╕", "╘", "╛", "╤", "╞", "╡", "╧"}
	DoubleSingleLineTable = &GraphicStringTableSymbols{"─", "║", "╫", "╓", "╖", "╙", "╜", "╥", "╟", "╢", "╨"}
	MonoTable             = &GraphicStringTableSymbols{"#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#"}
)

Standard graphic table drawing definitions.

Functions

func CamelCaseSplit added in v1.3.7

func CamelCaseSplit(src string) []string

CamelCaseSplit splits a camel case string into a slice.

func ChunkSplit added in v1.3.7

func ChunkSplit(s string, size int, spaceSplit bool) []string

ChunkSplit splits a string into chunks of a defined size. Attempts to only split at white space characters if spaceSplit is set.

func ConvertToJSONMarshalableObject added in v1.4.0

func ConvertToJSONMarshalableObject(v interface{}) interface{}

ConvertToJSONMarshalableObject converts container contents into objects which can be converted into JSON strings.

func ConvertToPrettyString added in v1.3.7

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

func CreateDisplayString(str string) string

CreateDisplayString changes all "_" characters into spaces and properly capitalizes the resulting string.

func GenerateRollingString

func GenerateRollingString(seq string, size int) string

GenerateRollingString creates a string by repeating a given string pattern.

func GlobStartingLiterals

func GlobStartingLiterals(glob string) string

GlobStartingLiterals gets the first literals of a glob string.

func GlobToRegex

func GlobToRegex(glob string) (string, error)

GlobToRegex converts a given glob expression into a regular expression.

func IndexOf

func IndexOf(str string, slice []string) int

IndexOf returns the index of str in slice or -1 if it does not exist.

func IsAlphaNumeric

func IsAlphaNumeric(str string) bool

IsAlphaNumeric checks if a string contains only alpha numerical characters or "_".

func IsTrueValue

func IsTrueValue(str string) bool

IsTrueValue checks if a given string is a true value.

func LengthConstantEquals

func LengthConstantEquals(str1 []byte, str2 []byte) bool

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

func LevenshteinDistance(str1, str2 string) int

LevenshteinDistance computes the Levenshtein distance between two strings.

func LongestCommonPrefix

func LongestCommonPrefix(s []string) string

LongestCommonPrefix determines the longest common prefix of a given list of strings.

func MD5HexString

func MD5HexString(str string) string

MD5HexString calculates the MD5 sum of a string and returns it as hex string.

func MapKeys

func MapKeys(m map[string]interface{}) []string

MapKeys returns the keys of a map as a sorted list.

func Plural

func Plural(l int) string

Plural returns the string 's' if the parameter is greater than one or if the parameter is 0.

func PrintCSVTable

func PrintCSVTable(ss []string, c int) string

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

func PrintStringTable(ss []string, c int) string

PrintStringTable prints a given list of strings as table with c columns.

func ProperTitle

func ProperTitle(input string) string

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 QuoteCLIArgs(args []string) string

func RuneSliceToString

func RuneSliceToString(buf []rune) string

RuneSliceToString converts a slice of runes into a string.

func StringToRuneSlice

func StringToRuneSlice(s string) []rune

StringToRuneSlice converts a string into a slice of runes.

func StripCStyleComments

func StripCStyleComments(text []byte) []byte

StripCStyleComments strips out C-Style comments from a given string.

func StripUniformIndentation

func StripUniformIndentation(s string) string

StripUniformIndentation removes uniform indentation from a string.

func ToUnixNewlines

func ToUnixNewlines(s string) string

ToUnixNewlines converts all newlines in a given string to unix newlines.

func TrimBlankLines

func TrimBlankLines(s string) string

TrimBlankLines removes blank initial and trailing lines.

func VersionStringCompare

func VersionStringCompare(str1, str2 string) int

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

type GlobParseError struct {
	Msg  string
	Pos  int
	Glob string
}

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.

Jump to

Keyboard shortcuts

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