Documentation
¶
Index ¶
- Variables
- 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 UnsafeString(b []byte) string
- 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) Write(bytes []byte) (int, error)
- 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) 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 InitTemplate = NewTemplate
for backward compability
Functions ¶
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 UnsafeString ¶
UnsafeString returns the string under byte buffer
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) 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, to dst and returns the extended buffer.
func (*Builder) WriteInt ¶
WriteInt appends the string form of the integer i, as generated by FormatInt, to dst and returns the extended buffer.
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" },
}