Documentation
¶
Overview ¶
Package strings provides high-performance, zero-copy string utilities with pooling for Nebula
Index ¶
- func BuildLargeString(fn func(*Builder)) string
- func BuildMediumString(fn func(*Builder)) string
- func BuildString(fn func(*Builder)) string
- func BuildWith(size BuilderSize, fn func(*Builder)) string
- func BytesToString(b []byte) string
- func Clone(s string) string
- func Compare(a, b string) int
- func Concat(strings ...string) string
- func Contains(s, substr string) bool
- func HasPrefix(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func Index(s, substr string) int
- func Join(strings []string, delimiter string) string
- func JoinPooled(strings []string, delimiter string) string
- func PutBuilder(builder *Builder, size BuilderSize)
- func Split(s, delimiter string) []string
- func Sprintf(format string, args ...interface{}) string
- func StringToBytes(s string) []byte
- func TrimSpace(s string) string
- func ValueToString(value interface{}) string
- type Builder
- func (b *Builder) Bytes() []byte
- func (b *Builder) Cap() int
- func (b *Builder) Grow(n int)
- func (b *Builder) Len() int
- func (b *Builder) Reset()
- func (b *Builder) String() string
- func (b *Builder) Write(p []byte) (n int, err error)
- func (b *Builder) WriteByte(c byte)
- func (b *Builder) WriteBytes(data []byte)
- func (b *Builder) WriteString(s string)
- type BuilderSize
- type CSVBuilder
- type Intern
- type Pool
- type SQLBuilder
- func (sb *SQLBuilder) Close()
- func (sb *SQLBuilder) String() string
- func (sb *SQLBuilder) WriteIdentifier(name string) *SQLBuilder
- func (sb *SQLBuilder) WriteInt(value int64) *SQLBuilder
- func (sb *SQLBuilder) WriteQuery(query string) *SQLBuilder
- func (sb *SQLBuilder) WriteSpace() *SQLBuilder
- func (sb *SQLBuilder) WriteStringLiteral(value string) *SQLBuilder
- type URLBuilder
- func (ub *URLBuilder) AddParam(key, value string) *URLBuilder
- func (ub *URLBuilder) AddParamBool(key string, value bool) *URLBuilder
- func (ub *URLBuilder) AddParamInt(key string, value int) *URLBuilder
- func (ub *URLBuilder) AddParams(params map[string]string) *URLBuilder
- func (ub *URLBuilder) AddPath(segments ...string) *URLBuilder
- func (ub *URLBuilder) Close()
- func (ub *URLBuilder) Query() string
- func (ub *URLBuilder) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildLargeString ¶
BuildLargeString provides a way to build large strings
func BuildMediumString ¶
BuildMediumString provides a way to build medium-sized strings
func BuildString ¶
BuildString provides a simple way to build strings with a function
func BuildWith ¶
func BuildWith(size BuilderSize, fn func(*Builder)) string
BuildWith provides a functional approach to string building
func BytesToString ¶
BytesToString converts byte slice to string without allocation WARNING: The returned string shares memory with the byte slice. Do not modify the byte slice after calling this function.
func JoinPooled ¶
JoinPooled efficiently joins strings using pooled builder
func PutBuilder ¶
func PutBuilder(builder *Builder, size BuilderSize)
PutBuilder returns a builder to the appropriate pool
func Split ¶
Split splits string by delimiter without allocating intermediate strings Returns a slice of string views into the original string
func StringToBytes ¶
StringToBytes converts string to byte slice without allocation WARNING: The returned byte slice shares memory with the string. Do not modify the returned slice.
func ValueToString ¶
func ValueToString(value interface{}) string
ValueToString efficiently converts interface{} values to strings This replaces fmt.Sprintf("%v", value) in hot paths like CSV processing
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides efficient string building with zero-copy operations
func GetBuilder ¶
func GetBuilder(size BuilderSize) *Builder
GetBuilder retrieves a pooled builder of the specified size
func (*Builder) WriteBytes ¶
WriteBytes appends bytes to the builder
func (*Builder) WriteString ¶
WriteString appends a string to the builder
type BuilderSize ¶
type BuilderSize int
BuilderSize represents different builder sizes
const ( Small BuilderSize = iota // < 1KB Medium // 1KB - 16KB Large // 16KB+ )
type CSVBuilder ¶
type CSVBuilder struct {
// contains filtered or unexported fields
}
CSVBuilder provides optimized CSV string building
func NewCSVBuilder ¶
func NewCSVBuilder(estimatedRows, estimatedCols int) *CSVBuilder
NewCSVBuilder creates a new CSV builder
func (*CSVBuilder) Close ¶
func (cb *CSVBuilder) Close()
Close releases the builder back to the pool
func (*CSVBuilder) String ¶
func (cb *CSVBuilder) String() string
String returns the built CSV string
func (*CSVBuilder) WriteHeader ¶
func (cb *CSVBuilder) WriteHeader(headers []string)
WriteHeader writes CSV header
func (*CSVBuilder) WriteRow ¶
func (cb *CSVBuilder) WriteRow(fields []string)
WriteRow writes a CSV row
type Intern ¶
type Intern struct {
// contains filtered or unexported fields
}
Intern provides string interning to reduce memory usage
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a pool of string builders
type SQLBuilder ¶
type SQLBuilder struct {
// contains filtered or unexported fields
}
SQLBuilder provides optimized SQL query building
func NewSQLBuilder ¶
func NewSQLBuilder(estimatedLength int) *SQLBuilder
NewSQLBuilder creates a new SQL builder
func (*SQLBuilder) Close ¶
func (sb *SQLBuilder) Close()
Close releases the builder back to the pool
func (*SQLBuilder) String ¶
func (sb *SQLBuilder) String() string
String returns the built SQL query
func (*SQLBuilder) WriteIdentifier ¶
func (sb *SQLBuilder) WriteIdentifier(name string) *SQLBuilder
WriteIdentifier writes a quoted identifier
func (*SQLBuilder) WriteInt ¶
func (sb *SQLBuilder) WriteInt(value int64) *SQLBuilder
WriteInt writes an integer value
func (*SQLBuilder) WriteQuery ¶
func (sb *SQLBuilder) WriteQuery(query string) *SQLBuilder
WriteQuery writes a SQL query part
func (*SQLBuilder) WriteSpace ¶
func (sb *SQLBuilder) WriteSpace() *SQLBuilder
WriteSpace adds a space
func (*SQLBuilder) WriteStringLiteral ¶
func (sb *SQLBuilder) WriteStringLiteral(value string) *SQLBuilder
WriteStringLiteral writes a quoted string literal
type URLBuilder ¶
type URLBuilder struct {
// contains filtered or unexported fields
}
URLBuilder provides optimized URL building
func NewFormBuilder ¶
func NewFormBuilder() *URLBuilder
NewFormBuilder creates a new form builder (for application/x-www-form-urlencoded) This is essentially a URLBuilder without a base URL
func NewURLBuilder ¶
func NewURLBuilder(baseURL string) *URLBuilder
NewURLBuilder creates a new URL builder
func (*URLBuilder) AddParam ¶
func (ub *URLBuilder) AddParam(key, value string) *URLBuilder
AddParam adds a URL parameter (with proper encoding)
func (*URLBuilder) AddParamBool ¶
func (ub *URLBuilder) AddParamBool(key string, value bool) *URLBuilder
AddParamBool adds a boolean parameter
func (*URLBuilder) AddParamInt ¶
func (ub *URLBuilder) AddParamInt(key string, value int) *URLBuilder
AddParamInt adds an integer parameter
func (*URLBuilder) AddParams ¶
func (ub *URLBuilder) AddParams(params map[string]string) *URLBuilder
AddParams adds multiple parameters
func (*URLBuilder) AddPath ¶
func (ub *URLBuilder) AddPath(segments ...string) *URLBuilder
AddPath adds path segments to the URL
func (*URLBuilder) Close ¶
func (ub *URLBuilder) Close()
Close releases the builder back to the pool
func (*URLBuilder) Query ¶
func (ub *URLBuilder) Query() string
Query returns just the query string (without the base URL) This is useful for form-encoded POST bodies