Documentation ¶
Overview ¶
Package stringutil contains utility functions for working with strings.
Index ¶
- Constants
- func AppendIfMissing(slice []string, i string) []string
- func ByteToHexASCII(b []byte) []byte
- func Clean(s []string) []string
- func CleanWhiteSpace(s []string) []string
- func ConstantTimeComparison(expected, actual string) bool
- func Contains(slice []string, i string) bool
- func Dash(s string) string
- func DecodeMessage(messageString string, target proto.Message) error
- func Detemplate(template string, rendered string) (map[string]string, error)
- func EncodeMessage(message proto.Message) (string, error)
- func Filter(ss []string, filter func(string) bool) []string
- func GetSchemaName(obj proto.Message) (name string)
- func IsEmpty(s string) bool
- func IsWhiteSpace(s string) bool
- func LastRune(s string) rune
- func LowerCamelCase(s string) string
- func MakeASCIIZeros(count uint) []byte
- func NewCharacterMismatchError(templateIndex int, renderedIndex int) errors.TracerError
- func NullTerminatedString(b []byte) string
- func NumericOnly(s string) string
- func Obfuscate(raw string, number int, direction Direction, obfuscator string) string
- func ObfuscateLeft(raw string, number int, obfuscator string) string
- func ObfuscateLeftPercent(raw string, percent int, obfuscator string) string
- func ObfuscatePercent(raw string, percent int, direction Direction, obfuscator string) string
- func ObfuscateRight(raw string, number int, obfuscator string) string
- func ObfuscateRightPercent(raw string, percent int, obfuscator string) string
- func PSPrint(prefix string, m map[string]string) string
- func Pointer(str string) *string
- func Reverse(s string) string
- func RuneAtIndex(s string, i int) rune
- func SafeSubstring(value string, start int, end int) string
- func SprintHex(b []byte) string
- func Underscore(s string) string
- func UpperCamelCase(s string) string
- type CharacterMismatchError
- type Direction
- type TagOptions
Constants ¶
const ( // DOpen is the character sequence used to determine when a // block of templated variable starts. DOpen = "{{" // DClose is the character sequence used to determine when a // block of templated variable closes. DClose = "}}" // DOpenLen is the length of the DOpen characters DOpenLen = len(DOpen) // DCloseLen is the length of the DClose characters DCloseLen = len(DClose) )
Variables ¶
This section is empty.
Functions ¶
func AppendIfMissing ¶
AppendIfMissing adds a string to a slice if it's not already in it
func ByteToHexASCII ¶
ByteToHexASCII returns a byte slice containing the hex representation of the passed byte array in ASCII characters.
func CleanWhiteSpace ¶
CleanWhiteSpace removes all strings in the passed slice that contain only white space.
func ConstantTimeComparison ¶
ConstantTimeComparison evaluates strings in a constant time to avoid hack attempts based on string comparison response rates
func DecodeMessage ¶ added in v2.17.0
DecodeMessage from a string
func Detemplate ¶
Detemplate takes a pattern with template style markup and a rendered template and attempts to construct the context that would be fed to generate the rendering. NOTE: This function does not support sequential template variables. e.g. 'test {{id1}}{{id2}}' as there is no way of knowing where one would end
and the next would begin.
func EncodeMessage ¶ added in v2.17.0
EncodeMessage as a string
func Filter ¶
Filter removes all strings from a slice of strings that do not have a value of 'true' when passed to the filter function.
func GetSchemaName ¶
GetSchemaName from an object for use in the schema field on a routed message payload.
func IsEmpty ¶
IsEmpty returns a bool indicating that the passed string is Empty. used primarily as a filter function.
func IsWhiteSpace ¶
IsWhiteSpace returns a bool indicating whether the passed string is composed entirely of whitespace characters.
func LastRune ¶
LastRune returns the last rune in a string. If the string is Empty the default value for rune is returned.
func LowerCamelCase ¶
LowerCamelCase converts a string to camel case with the first letter lowercase
func MakeASCIIZeros ¶
MakeASCIIZeros in a byte array of the passed size.
func NewCharacterMismatchError ¶
func NewCharacterMismatchError(templateIndex int, renderedIndex int) errors.TracerError
NewCharacterMismatchError occurs during demplating and indicates where in the template the issue happened
func NullTerminatedString ¶
NullTerminatedString from the passed byte array. Note: this only works with ASCII or UTF-8
func NumericOnly ¶
NumericOnly returns only the numeric characters, in order, in the passed string as a new string.
func Obfuscate ¶
Obfuscate the raw string from the given Direction, with the given number of repetition of the obfuscator string.
func ObfuscateLeft ¶
ObfuscateLeft will obfuscate the raw string from the left hand side with the given number of repitions of the obfuscator string.
func ObfuscateLeftPercent ¶ added in v2.3.0
ObfuscateLeftPercent obfuscates percent of string, leaves at least 1 character
func ObfuscatePercent ¶ added in v2.3.0
ObfuscatePercent obfuscates percent of string, leaves at least 1 character
func ObfuscateRight ¶
ObfuscateRight will obfuscate the raw string from the right hand side with the given number of repitions of the obfuscator string.
func ObfuscateRightPercent ¶ added in v2.3.0
ObfuscateRightPercent obfuscates percent of string, leaves at least 1 character
func RuneAtIndex ¶
RuneAtIndex returns the rune located at the specified index in the passed string. Supports negative indexing.
func SafeSubstring ¶
SafeSubstring returns a substring that should be safe to use with strings that contain non-ascii characters, with python style indexing. If end equals 0 it will be interpreted as the end of the string.
func SprintHex ¶
SprintHex the passed byte array as a string of Hexadecimal numbers space separated.
func Underscore ¶
Underscore converts strings to underscored version (e.g. CamelCase to camel_case)
func UpperCamelCase ¶
UpperCamelCase converts a string to camel case with the first letter uppercase
Types ¶
type CharacterMismatchError ¶
type CharacterMismatchError struct { TemplateIndex int RenderedIndex int // contains filtered or unexported fields }
CharacterMismatchError returned when the characters in a rendered template do not match those in the template outside of a phrase.
func (*CharacterMismatchError) Error ¶
func (err *CharacterMismatchError) Error() string
func (*CharacterMismatchError) Trace ¶
func (err *CharacterMismatchError) Trace() []string
Trace returns the stack trace for the error
type TagOptions ¶
type TagOptions []string
TagOptions is the string following a comma in a struct field's tag, or the empty string. It does not include the leading comma.
func ParseTag ¶
func ParseTag(tag string) (string, TagOptions)
ParseTag splits a struct field's tag into its name and comma-separated options.
func (TagOptions) Contains ¶
func (o TagOptions) Contains(optionName string) bool
Contains reports whether a comma-separated list of options contains a particular substr flag. substr must be surrounded by a string boundary or commas.