Categorygithub.com/msaf1980/go-stringutils
modulepackage
0.1.6
Repository: https://github.com/msaf1980/go-stringutils.git
Documentation: pkg.go.dev

# README

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

# Functions

Clone returns a fresh copy of s.
Clone returns a fresh copy of s.
EqualFold tests ascii strings for equality case-insensitively.
EqualFoldBytes tests ascii slices for equality case-insensitively.
NewTemplate parse and split format string (format string stored in first field) @format Format string like 'string %{param} %{param1.param2}'.
No description provided by the author
Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new.
ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new.
Reverse return reversed string (rune-wise left to right).
ReverseSegments return reversed string by segments around delimiter.
Split return splitted slice (use pre-allocated buffer) (realloc if needed).
Split2 return the split string results (without memory allocations) If sep string not found: 's' '' 1 If s or sep string is empthy: 's' '' 1 In other cases: 's0' 's2' 2.
SplitByte return splitted slice (use pre-allocated buffer) (realloc if needed).
SplitRune return splitted slice (use pre-allocated buffer) (realloc if needed).
ToLower converts ascii string to lower-case.
ToLowerBytes converts ascii slice to lower-case in-place.
ToUpper converts ascii string to upper-case.
ToUpperBytes converts ascii slice to upper-case in-place.
Trim is the equivalent of strings.Trim.
TrimBytes is the equivalent of bytes.Trim.
TrimLeft is the equivalent of strings.TrimLeft.
TrimLeftBytes is the equivalent of bytes.TrimLeft.
TrimRight is the equivalent of strings.TrimRight.
TrimRightBytes is the equivalent of bytes.TrimRight.
No description provided by the author
UnsafeString returns the string under byte buffer.
UnsafeStringBytePtr returns the string byte ptr.
UnsafeStringBytes returns the string bytes.
UnsafeStringFromPtr returns the string with specific length under byte buffer.
UUID generates an universally unique identifier (UUID).
WriteString writes the contents of the string s to w, which accepts a slice of bytes.

# Variables

for backward compability.
compability with Golang 1.20 proposal https://github.com/golang/go/issues/53003.
compability with Golang 1.20 proposal https://github.com/golang/go/issues/53003.

# Structs

A Builder is used to efficiently build a string using Write methods (with better perfomance than strings.Builder).

# Type aliases

Template parsed and splited format string (stored in first field).