Skip to content

msaf1980/go-stringutils

Repository files navigation

stringutils

Some string utils

UnsafeString([]byte) string return unsafe string from bytes slice indirectly (without allocation)

UnsafeStringFromPtr(*byte, length) string return unsafe string from bytes slice pointer indirectly (without allocation)

UnsafeStringBytes(*string) []bytes return unsafe string bytes indirectly (without allocation)

Split2(s string, sep string) (string, string, int) Split2 return the split string results (without memory allocations). Use Index for find separator.

Split(s string, sep string, buf []string) []string // Split return splitted slice (use pre-allocated buffer, reallocated if needed). Use Index for find separator. SplitByte(s string, sep byte, buf []string) []string // SplitByte return splitted slice (use pre-allocated buffer, reallocated if needed). Use Index for find separator. SplitRune(s string, sep rune, buf []string) []string // SplitByte return splitted slice (use pre-allocated buffer, reallocated if needed). Use Index for find separator. For Unicode long-width rune it's slower than Split

SplitN(s string, sep string, buf []string) []string // SplitN deprecated and removed, use Split

Reverse(string) string return reversed string (rune-wise left to right) ReverseSegments(string, delim) string return reversed string by segments around string delimiter (ReverseSegments("hello, world", ", ") return world, hello).

Replace(s, old, new string, n int) (string, changed) // Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new. Also return change flag.

ReplaceAll(s, old, new string) (string, changed) // Replace returns a copy of the string s with all non-overlapping instances of old replaced by new. Also return change flag.

WriteString(w io.Writer, s string) (int, error) writes the contents of the string s to w, which accepts a slice of bytes. No bytes alloation instead of io.WriteString.

Builder very simular to strings.Builder, but has better perfomance in some cases (reallocate with scale 2, if needed, also append numbers in-place) (at golang 1.14).

Template is a simple templating system

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages