strings

package
v0.0.0-...-be384fd Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASCIITrim

func ASCIITrim(s string) (string, error)

ASCIITrim removes spaces from an a ASCII string, erroring if the sequence is not an ASCII string.

func LazyBlockHash

func LazyBlockHash(block interface{ Hash() tmbytes.HexBytes }) fmt.Stringer

LazyBlockHash defers block Hash until the Stringer interface is invoked. This is particularly useful for avoiding calling Sprintf when debugging is not active.

As a result, if you use this type in go routines or defer statements it's possible to pass an argument to LazyBlockHash that has one value at the call site and a different value when the String() is evaluated, which may lead to unexpected outcomes. In these situations, either be *extremely* careful about the arguments passed to this function or use fmt.Sprintf.

The implementation also caches the output of the string form of the block hash when String() is called, so subsequent calls will produce the same result.

func LazySprintf

func LazySprintf(t string, args ...interface{}) fmt.Stringer

LazySprintf creates a fmt.Stringer implementation with similar semantics as fmt.Sprintf, *except* that the string is built when String() is called on the object. This means that format arguments are resolved/captured into string format when String() is called, and not, as in fmt.Sprintf when that function returns.

As a result, if you use this type in go routines or defer statements it's possible to pass an argument to LazySprintf which has one value at the call site and a different value when the String() is evaluated, which may lead to unexpected outcomes. In these situations, either be *extremely* careful about the arguments passed to this function or use fmt.Sprintf.

The implementation also caches the output of the underlying fmt.Sprintf statement when String() is called, so subsequent calls will produce the same result.

func LazyStringer

func LazyStringer(v fmt.Stringer) fmt.Stringer

LazyStringer captures a fmt.Stringer implementation resolving the underlying string *only* when the String() method is called and caching the result for future use.

func SplitAndTrimEmpty

func SplitAndTrimEmpty(s, sep, cutset string) []string

SplitAndTrimEmpty slices s into all subslices separated by sep and returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed. If sep is empty, SplitAndTrim splits after each UTF-8 sequence. First part is equivalent to strings.SplitN with a count of -1. also filter out empty strings, only return non-empty strings.

func StringSliceEqual

func StringSliceEqual(a, b []string) bool

StringSliceEqual checks if string slices a and b are equal

Types

This section is empty.

Jump to

Keyboard shortcuts

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