Documentation ¶
Index ¶
- Variables
- func Clone(s string) string
- func CloneBytes(b []byte) []byte
- func EqualFold(b, s string) bool
- func EqualFoldBytes(b, s []byte) bool
- func NewTemplateParam(s string) templateParam
- func Replace(s, old, new string, n int) (string, bool)
- func ReplaceAll(s, old, new string) (string, bool)
- func Reverse(s string) string
- func ReverseSegments(target, delim string) string
- func Split(s string, sep string, buf []string) []string
- func Split2(s string, sep string) (string, string, int)
- func SplitByte(s string, sep byte, buf []string) []string
- func SplitRune(s string, sep rune, buf []string) []string
- func ToLower(b string) string
- func ToLowerBytes(b []byte) []byte
- func ToUpper(b string) string
- func ToUpperBytes(b []byte) []byte
- func Trim(s string, cutset byte) string
- func TrimBytes(b []byte, cutset byte) []byte
- func TrimLeft(s string, cutset byte) string
- func TrimLeftBytes(b []byte, cutset byte) []byte
- func TrimRight(s string, cutset byte) string
- func TrimRightBytes(b []byte, cutset byte) []byte
- func UUID() string
- func UnsafeBytes(ptr *byte, length, cap int) (b []byte)
- func UnsafeString(b []byte) string
- func UnsafeStringBytePtr(s string) *byte
- func UnsafeStringBytes(s *string) []byte
- func UnsafeStringFromPtr(ptr *byte, length int) (s string)
- func WriteString(w io.Writer, s string) (n int, err error)
- type Builder
- func (sb *Builder) Bytes() []byte
- func (sb *Builder) Cap() int
- func (sb *Builder) Flush() error
- func (sb *Builder) Grow(capacity int)
- func (sb *Builder) Len() int
- func (sb *Builder) Map(mapping func(rune) rune, s string)
- func (sb *Builder) Release()
- func (sb *Builder) Reset()
- func (sb *Builder) String() string
- func (sb *Builder) Truncate(length int)
- func (sb *Builder) Write(bytes []byte) (int, error)
- func (sb *Builder) WriteBool(v bool)
- func (sb *Builder) WriteByte(c byte) error
- func (sb *Builder) WriteBytes(bytes []byte)
- func (sb *Builder) WriteFloat(f float64, fmt byte, prec, bitSize int)
- func (sb *Builder) WriteInt(i int64, base int)
- func (sb *Builder) WriteQuote(s string)
- func (sb *Builder) WriteQuoteRune(r rune)
- func (sb *Builder) WriteQuoteRuneToASCII(r rune)
- func (sb *Builder) WriteQuoteRuneToGraphic(r rune)
- func (sb *Builder) WriteQuoteToASCII(s string)
- func (sb *Builder) WriteQuoteToGraphic(s string)
- func (sb *Builder) WriteRune(r rune) (int, error)
- func (sb *Builder) WriteString(s string) (int, error)
- func (sb *Builder) WriteStringLower(s string)
- func (sb *Builder) WriteStringUpper(s string)
- func (sb *Builder) WriteUint(i uint64, base int)
- type Template
Constants ¶
This section is empty.
Variables ¶
var ( String func(ptr *byte, length int) string = UnsafeStringFromPtr StringData func(str string) *byte = UnsafeStringBytePtr )
compability with Golang 1.20 proposal https://github.com/golang/go/issues/53003
var InitTemplate = NewTemplate
for backward compability
Functions ¶
func Clone ¶ added in v0.1.4
Clone returns a fresh copy of s. It guarantees to make a copy of s into a new allocation, which can be important when retaining only a small substring of a much larger string. Using Clone can help such programs use less memory. Of course, since using Clone makes a copy, overuse of Clone can make programs use more memory. Clone should typically be used only rarely, and only when profiling indicates that it is needed. For strings of length zero the string "" will be returned and no allocation is made.
func CloneBytes ¶ added in v0.1.5
Clone returns a fresh copy of s. It guarantees to make a copy of s into a new allocation, which can be important when retaining only a small substring of a much larger string. Using Clone can help such programs use less memory. Of course, since using Clone makes a copy, overuse of Clone can make programs use more memory. Clone should typically be used only rarely, and only when profiling indicates that it is needed. For strings of length zero the string "" will be returned and no allocation is made.
func EqualFoldBytes ¶ added in v0.1.5
EqualFoldBytes tests ascii slices for equality case-insensitively
func NewTemplateParam ¶ added in v0.1.1
func NewTemplateParam(s string) templateParam
func Replace ¶ added in v0.0.13
Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new. Also return change flag. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n < 0, there is no limit on the number of replacements.
func ReplaceAll ¶ added in v0.0.13
ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new. Also return change flag. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.
func ReverseSegments ¶ added in v0.0.12
ReverseSegments return reversed string by segments around delimiter.
func Split ¶ added in v0.1.0
Split return splitted slice (use pre-allocated buffer) (realloc if needed)
func Split2 ¶
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
func SplitByte ¶ added in v0.1.0
SplitByte return splitted slice (use pre-allocated buffer) (realloc if needed)
func SplitRune ¶ added in v0.1.0
SplitRune return splitted slice (use pre-allocated buffer) (realloc if needed)
func ToLowerBytes ¶ added in v0.1.5
ToLowerBytes converts ascii slice to lower-case in-place.
func ToUpperBytes ¶ added in v0.1.5
ToUpperBytes converts ascii slice to upper-case in-place.
func TrimLeftBytes ¶ added in v0.1.5
TrimLeftBytes is the equivalent of bytes.TrimLeft
func TrimRightBytes ¶ added in v0.1.5
TrimRightBytes is the equivalent of bytes.TrimRight
func UUID ¶ added in v0.1.5
func UUID() string
UUID generates an universally unique identifier (UUID)
func UnsafeBytes ¶ added in v0.1.5
func UnsafeString ¶
UnsafeString returns the string under byte buffer
func UnsafeStringBytePtr ¶ added in v0.1.5
UnsafeStringBytePtr returns the string byte ptr
func UnsafeStringBytes ¶
UnsafeStringBytes returns the string bytes
func UnsafeStringFromPtr ¶
UnsafeStringFromPtr returns the string with specific length under byte buffer
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
A Builder is used to efficiently build a string using Write methods (with better perfomance than strings.Builder). It minimizes memory copying. The zero value is ready to use. Do not copy a non-zero Builder.
func (*Builder) Cap ¶
Cap returns the capacity of the builder's underlying byte slice. It is the total space allocated for the string being built and includes any bytes already written.
func (*Builder) Grow ¶
Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation.
func (*Builder) Map ¶
based on strings.Map Map returns a copy of the string s with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the string with no replacement.
func (*Builder) Release ¶
func (sb *Builder) Release()
Release resets the Builder to be empty and free buffer
func (*Builder) Truncate ¶ added in v0.1.3
Truncate descrease the Builder length (dangerouse for partually truncated UTF strings).
func (*Builder) WriteBool ¶ added in v0.1.2
WriteBool appends the string form of the bool v, as generated by FormatBool.
func (*Builder) WriteBytes ¶
WriteBytes appends the contents of p to b's buffer.
func (*Builder) WriteFloat ¶
WriteFloat appends the string form of the floating-point number f, as generated by FormatFloat.
func (*Builder) WriteInt ¶
WriteInt appends the string form of the integer i, as generated by FormatInt.
func (*Builder) WriteQuote ¶ added in v0.1.2
WriteQuote appends the string form of the quoted string s, as generated by Quote.
func (*Builder) WriteQuoteRune ¶ added in v0.1.2
WriteQuoteRune appends the string form of the quoted rune r, as generated by QuoteRune.
func (*Builder) WriteQuoteRuneToASCII ¶ added in v0.1.2
WriteQuoteRuneToASCII appends the string form of the single-quoted rune r, as generated by QuoteRuneToASCII.
func (*Builder) WriteQuoteRuneToGraphic ¶ added in v0.1.2
WriteQuoteRuneToGraphic appends the string form of the quoted rune r, as generated by QuoteRuneToGraphic.
func (*Builder) WriteQuoteToASCII ¶ added in v0.1.2
WriteQuoteToASCII appends the string form of the single-quoted string s, as generated by QuoteToASCII.
func (*Builder) WriteQuoteToGraphic ¶ added in v0.1.2
WriteQuoteToGraphic appends the string form of the quoted string s, as generated by QuoteToGraphic.
func (*Builder) WriteRune ¶
WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer.
func (*Builder) WriteString ¶
WriteString appends the contents of s to b's buffer.
func (*Builder) WriteStringLower ¶
based on strings.ToLower ToLower returns s with all Unicode letters mapped to their lower case.
func (*Builder) WriteStringUpper ¶
based on strings.ToUpper ToUpper returns s with all Unicode letters mapped to their upper case.
type Template ¶
type Template []interface{}
Template parsed and splited format string (stored in first field)
func NewTemplate ¶ added in v0.1.1
NewTemplate parse and split format string (format string stored in first field)
@format Format string like 'string %{param} %{param1.param2}'
func (*Template) Execute ¶
Execute process template with mapped params
@Params Params in map[string]interface{}
params := map[string]interface{}{ "param": "URL", "param1": map[string]interface{}{ "param2": "2" }, }
func (*Template) ExecutePartial ¶ added in v0.1.1
ExecutePartial process template with mapped params, if parameter not found - use segment as is (without error)
@Params Params in map[string]interface{}
params := map[string]interface{}{ "param": "URL", "param1": map[string]interface{}{ "param2": "2" }, }