Documentation
¶
Index ¶
- Variables
- func IndexOf(s, substr string) int
- func IsEmpty(s string) bool
- func IsEqual(s, value string) bool
- type Builder
- func (b *Builder) Cap() int
- func (b *Builder) Grow(n int)
- func (b *Builder) Len() int
- func (b *Builder) String() string
- func (b *Builder) Write(p []byte) (int, error)
- func (b *Builder) WriteByte(c byte) error
- func (b *Builder) WriteRune(r rune) (int, error)
- func (b *Builder) WriteString(s string) (int, error)
- type Case
- type MapFn
- type MathError
- type Number
- func (s Number) Float() float64
- func (s Number) Float32() float32
- func (s Number) Int() int
- func (s Number) Int16() int16
- func (s Number) Int32() int32
- func (s Number) Int64() int64
- func (s Number) Int8() int8
- func (s Number) String() string
- func (s Number) Uint() uint
- func (s Number) Uint16() uint16
- func (s Number) Uint32() uint32
- func (s Number) Uint64() uint64
- func (s Number) Uint8() uint8
- type Parser
- type Random
- type Reader
- func (r *Reader) Len() int
- func (r *Reader) Read(b []byte) (n int, err error)
- func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)
- func (r *Reader) ReadByte() (byte, error)
- func (r *Reader) ReadRune() (ch rune, size int, err error)
- func (r *Reader) Reset(s string)
- func (r *Reader) Seek(offset int64, whence int) (int64, error)
- func (r *Reader) Size() int64
- func (r *Reader) UnreadByte() error
- func (r *Reader) UnreadRune() error
- func (r *Reader) WriteTo(w io.Writer) (n int64, err error)
- type Replacer
- type ReverseFn
- type String
- func (s String) Builder() *Builder
- func (s String) Bytes() []byte
- func (s String) CharAt(index int) String
- func (s String) Concat(str ...Stringer) String
- func (s String) ConcatStrings(str ...string) String
- func (s String) Count(value string) int
- func (s String) Equal(value string) bool
- func (s String) HasPrefix(prefix string) bool
- func (s String) HasSuffix(suffix string) bool
- func (s String) Includes(substr string) bool
- func (s String) IndexOf(substr string) int
- func (s String) IsEmpty() bool
- func (s String) Length() int
- func (s String) Lines() iter.Seq[string]
- func (s String) Map(fn MapFn) String
- func (s String) Match(regex string) bool
- func (s String) Repeat(value string, count int) String
- func (s String) Replace(old, new string) String
- func (s String) Reverse() (result String)
- func (s String) ReverseFn(fn ReverseFn) (result String)
- func (s String) Runes() []rune
- func (s String) Search(regex string) []string
- func (s String) Slice(start, end int) String
- func (s String) Split(sep string) []string
- func (s String) SplitN(sep string, n int) []string
- func (s String) String() string
- func (s String) ToLowerCase() String
- func (s String) ToUpperCase() String
- func (s String) Trim(cutset string) (result String)
- func (s String) TrimEnd(cutset string) (result String)
- func (s String) TrimPrefix(prefix string) (result String)
- func (s String) TrimStart(cutset string) (result String)
- func (s String) TrimSuffix(suffix string) (result String)
- type Stringer
- type Strings
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnreadRuneAtBeginning is returned by [github.com/i9si-sistemas/stringx.Reader.UnreadRune] when the reader is at the beginning of the string. ErrUnreadRuneAtBeginning = errors.New("stringx.Reader.UnreadRune: at beginning of string") // ErrUnreadRuneNotRead is returned by [github.com/i9si-sistemas/stringx.Reader.UnreadRune] when the previous operation was not ReadRune. ErrUnreadRuneNotRead = errors.New("stringx.Reader.UnreadRune: previous operation was not ReadRune") )
var ( // ErrSeekInvalidWhence is returned by [github.com/i9si-sistemas/stringx.Reader.Seek] when the whence argument is invalid. ErrSeekInvalidWhence = errors.New("stringx.Reader.Seek: invalid whence") // ErrSeekNegativePosition is returned by [github.com/i9si-sistemas/stringx.Reader.Seek] when the position is negative. ErrSeekNegativePosition = errors.New("stringx.Reader.Seek: negative position") )
var ( // Space is the space character. Space = String(" ") // Dash is the dash character. Dash = String("-") // Zero is the zero character Zero = String("0") // Equals is the equals character Equals = String("=") // Tab is the tab character. Tab = String("\t") // Plus is the plus character. Plus = String("+") // NewLine is the newline character. NewLine = String("\n") )
var ( // ErrOldOrNewCannotBeEmpty is returned when either old or new slice is empty. ErrOldOrNewCannotBeEmpty = errors.New("stringx: old or new cannot be empty") // ErrOldAndNewMustHaveSameLen is returned when old and new slice have different length. ErrOldAndNewMustHaveSameLen = errors.New("stringx: old and new must have the same length") )
var Empty = String("")
Empty is an empty string.
var ErrInvalidExpression = MathError("Invalid expression")
ErrInvalidExpression is returned when the expression is invalid.
var ErrReadAtNegativeOffset = errors.New("stringx.Reader.ReadAt: negative offset")
ErrReadAtNegativeOffset is returned by github.com/i9si-sistemas/stringx.Reader.ReadAt when the offset is negative.
var ErrReaderEOF = io.EOF
ErrReaderEOF is returned when the reader reaches the end of the string.
var ErrUnreadByte = errors.New("stringx.Reader.UnreadByte: at beginning of string")
ErrUnreadByte is returned by github.com/i9si-sistemas/stringx.Reader.UnreadByte when the reader is at the beginning of the string.
var ErrWriteToInvalidWriteStringCount = errors.New(
"stringx.Reader.WriteTo: invalid WriteString count",
)
ErrWriteToInvalidWriteStringCount is returned by github.com/i9si-sistemas/stringx.Reader.WriteTo when the number of bytes written is not equal to the length of the string.
var Log = log.Println
Log is default printer for stringx.
Functions ¶
func IndexOf ¶ added in v1.5.9
IndexOf returns the index of the first occurrence of substr in s, or -1 if substr is not present in s.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
A Builder is used to efficiently build a string using Write methods.
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.
func (*Builder) Write ¶
Write appends the contents of p to b's buffer. Write always returns len(p), nil.
func (*Builder) WriteByte ¶
WriteByte appends the byte c to b's buffer. The returned error is always nil.
type Number ¶ added in v1.5.2
type Number struct {
// contains filtered or unexported fields
}
Number is a string wrapper for number.
func ParseNumber ¶ added in v1.5.2
ParseNumber returns a Number object.
type Parser ¶ added in v1.5.2
type Parser struct {
// contains filtered or unexported fields
}
Parser is a string parser.
func NewParser ¶ added in v1.5.2
NewParser creates a github.com/i9si-sistemas/stringx.Parser.
type Random ¶ added in v1.5.0
type Random interface {
// Index returns a valid random index based on the collection size.
Index() int
// MaxLength returns the maximum size of the string collection.
MaxLength() int
// Random returns a random string from the collection.
Random() String
}
Random defines an interface for selecting a random element from a string collection.
func NewRandomString ¶ added in v1.5.0
NewRandomString creates a new Random instance from a list of strings.
type Reader ¶ added in v1.4.0
type Reader struct {
// contains filtered or unexported fields
}
A Reader implements the io.Reader, io.ReaderAt, io.ByteReader, io.ByteScanner, io.RuneReader, io.RuneScanner, io.Seeker, and io.WriterTo interfaces by reading from a string. The zero value for Reader operates like a Reader of an empty string.
func NewReader ¶ added in v1.4.0
NewReader returns a new github.com/i9si-sistemas/stringx.Reader reading from s. It is similar to bytes.NewBufferString but more efficient and non-writable.
func (*Reader) Len ¶ added in v1.4.0
Len returns the number of bytes of the unread portion of the string.
func (*Reader) ReadAt ¶ added in v1.4.0
ReadAt implements the io.ReaderAt interface.
func (*Reader) ReadByte ¶ added in v1.4.0
ReadByte implements the io.ByteReader interface.
func (*Reader) ReadRune ¶ added in v1.4.0
ReadRune implements the io.RuneReader interface.
func (*Reader) Reset ¶ added in v1.4.0
Reset resets the github.com/i9si-sistemas/stringx.Reader to be reading from s.
func (*Reader) Size ¶ added in v1.4.0
Size returns the original length of the underlying string. Size is the number of bytes available for reading via github.com/i9si-sistemas/stringx.Reader.ReadAt. The returned value is always the same and is not affected by calls to any other method.
func (*Reader) UnreadByte ¶ added in v1.4.0
UnreadByte implements the io.ByteScanner interface.
func (*Reader) UnreadRune ¶ added in v1.4.0
UnreadRune implements the io.RuneScanner interface.
type Replacer ¶ added in v1.1.2
type Replacer struct {
// contains filtered or unexported fields
}
Replacer is a struct that holds a String and two slices of strings for replacement.
func NewReplacer ¶ added in v1.1.2
NewReplacer creates a new Replacer instance with the provided String and slices of old and new strings.
type String ¶
type String string
String is a functional string type.
func Convert ¶
Convert converts a Stringer to a String.
Example:
type Slice []any
func (s Slice) String() string {
return fmt.Sprintf("%v", s)
}
slice := Slice{1, 2, 3}
s := Convert(slice)
func Map ¶ added in v1.5.9
Map applies a function to each rune in the string, returning a new string
func New ¶ added in v1.6.0
New creates a new String from any type that implements Stringer or is a string.
stringx.New("hello") // String("hello")
stringx.New([]byte("hello")) // String("hello")
type NumberStr int
func (n NumberStr) String() string { return fmt.Sprint(n) }
stringx.New(NumberStr(123)) // String("123")
func (String) ConcatStrings ¶ added in v1.5.4
ConcatStrings concatenates the String with other strings.
func (String) IndexOf ¶
IndexOf returns the index of the first occurrence of substr in s, or -1 if substr is not present in s.
func (String) Lines ¶ added in v1.4.3
Lines returns an iterator over the newline-terminated lines in the string s.
func (String) Repeat ¶
Repeat returns a new String by repeating the specified `value` string `count` times and concatenating the result to the original String `s`.
example:
String("Go").Repeat("lang", 3) // returns "Golanglanglang"
Parameters:
value - the string to repeat count - the number of times to repeat the value
Returns:
A new String with the repeated value appended to the original.
func (String) Replace ¶
Replace performs the replacement of old strings with new strings in the String.
func (String) SplitN ¶ added in v1.4.1
SplitN splits the string s into substrings separated by sep.
- sep: the separator.
- n: the maximum number of substrings to return.
Example:
s := stringx.String("Hello, World !")
s.SplitN(stringx.Space.String(), 2) // ["Hello", "World !"]
func (String) ToLowerCase ¶
ToLowerCase converts the string to lower case. It uses the unicode.ToLower function to ensure proper handling of Unicode characters.
func (String) ToUpperCase ¶
ToUpperCase converts the string to upper case. It uses the unicode.ToUpper function to ensure proper handling of Unicode characters.
func (String) TrimPrefix ¶ added in v1.4.2
TrimPrefix removes all leading characters in prefix from the string.
func (String) TrimSuffix ¶ added in v1.4.2
TrimSuffix removes all trailing characters in suffix from the string.
type Stringer ¶
type Stringer interface {
// String returns the string representation of the object.
String() string
}
Stringer is an interface that can be converted to a string.