str

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Camel2Case

func Camel2Case(name string) string

func Case2Camel

func Case2Camel(name string) string

func Random

func Random(length int) string

func Substr

func Substr(str string, start int, length ...int) string

Substr returns a substring of a given string, starting at the specified index and with a specified length. It handles UTF-8 encoded strings.

Types

type Buffer

type Buffer struct {
	*bytes.Buffer
}

func NewBuffer

func NewBuffer() *Buffer

func (*Buffer) Append

func (b *Buffer) Append(i any) *Buffer

type ExcerptOption

type ExcerptOption struct {
	Radius   int
	Omission string
}

ExcerptOption is the option for Excerpt method

type String

type String struct {
	// contains filtered or unexported fields
}

func Of

func Of(value string) *String

Of creates a new String instance with the given value.

func (*String) After

func (s *String) After(search string) *String

After returns a new String instance with the substring after the first occurrence of the specified search string.

func (*String) AfterLast

func (s *String) AfterLast(search string) *String

AfterLast returns the String instance with the substring after the last occurrence of the specified search string.

func (*String) Append

func (s *String) Append(values ...string) *String

Append appends one or more strings to the current string.

func (*String) Basename

func (s *String) Basename(suffix ...string) *String

Basename returns the String instance with the basename of the current file path string, and trims the suffix based on the parameter(optional).

func (*String) Before

func (s *String) Before(search string) *String

Before returns the String instance with the substring before the first occurrence of the specified search string.

func (*String) BeforeLast

func (s *String) BeforeLast(search string) *String

BeforeLast returns the String instance with the substring before the last occurrence of the specified search string.

func (*String) Between

func (s *String) Between(start, end string) *String

Between returns the String instance with the substring between the given start and end strings.

func (*String) BetweenFirst

func (s *String) BetweenFirst(start, end string) *String

BetweenFirst returns the String instance with the substring between the first occurrence of the given start string and the given end string.

func (*String) Camel

func (s *String) Camel() *String

Camel returns the String instance in camel case.

func (*String) CharAt

func (s *String) CharAt(index int) string

CharAt returns the character at the specified index.

func (*String) Contains

func (s *String) Contains(values ...string) bool

Contains returns true if the string contains the given value or any of the values.

func (*String) ContainsAll

func (s *String) ContainsAll(values ...string) bool

ContainsAll returns true if the string contains all of the given values.

func (*String) Dirname

func (s *String) Dirname(levels ...int) *String

Dirname returns the String instance with the directory name of the current file path string.

func (*String) EndsWith

func (s *String) EndsWith(values ...string) bool

EndsWith returns true if the string ends with the given value or any of the values.

func (*String) Exactly

func (s *String) Exactly(value string) bool

Exactly returns true if the string is exactly the given value.

func (*String) Excerpt

func (s *String) Excerpt(phrase string, options ...ExcerptOption) *String

Excerpt returns the String instance truncated to the given length.

func (*String) Explode

func (s *String) Explode(delimiter string, limit ...int) []string

Explode splits the string by given delimiter string.

func (*String) Finish

func (s *String) Finish(value string) *String

Finish returns the String instance with the given value appended. If the given value already ends with the suffix, it will not be added twice.

func (*String) Headline

func (s *String) Headline() *String

Headline returns the String instance in headline case.

func (*String) Is

func (s *String) Is(patterns ...string) bool

Is returns true if the string matches any of the given patterns.

func (*String) IsAscii

func (s *String) IsAscii() bool

IsAscii returns true if the string contains only ASCII characters.

func (*String) IsEmpty

func (s *String) IsEmpty() bool

IsEmpty returns true if the string is empty.

func (*String) IsMap

func (s *String) IsMap() bool

IsMap returns true if the string is a valid Map.

func (*String) IsMatch

func (s *String) IsMatch(patterns ...string) bool

IsMatch returns true if the string matches any of the given patterns.

func (*String) IsNotEmpty

func (s *String) IsNotEmpty() bool

IsNotEmpty returns true if the string is not empty.

func (*String) IsSlice

func (s *String) IsSlice() bool

IsSlice returns true if the string is a valid Slice.

func (*String) IsUlid

func (s *String) IsUlid() bool

IsUlid returns true if the string is a valid ULID.

func (*String) IsUuid

func (s *String) IsUuid() bool

IsUuid returns true if the string is a valid UUID.

func (*String) Kebab

func (s *String) Kebab() *String

Kebab returns the String instance in kebab case.

func (*String) LTrim

func (s *String) LTrim(characters ...string) *String

Ltrim returns the String instance with the leftmost occurrence of the given value removed.

func (*String) LcFirst

func (s *String) LcFirst() *String

LcFirst returns the String instance with the first character lowercased.

func (*String) Length

func (s *String) Length() int

Length returns the length of the string.

func (*String) Limit

func (s *String) Limit(limit int, end ...string) *String

Limit returns the String instance truncated to the given length.

func (*String) Lower

func (s *String) Lower() *String

Lower returns the String instance in lower case.

func (*String) Mask

func (s *String) Mask(character string, index int, length ...int) *String

Mask returns the String instance with the given character masking the specified number of characters.

func (*String) Match

func (s *String) Match(pattern string) *String

Match returns the String instance with the first occurrence of the given pattern.

func (*String) MatchAll

func (s *String) MatchAll(pattern string) []string

MatchAll returns all matches for the given regular expression.

func (*String) NewLine

func (s *String) NewLine(count ...int) *String

NewLine appends one or more new lines to the current string.

func (*String) PadBoth

func (s *String) PadBoth(length int, pad ...string) *String

PadBoth returns the String instance padded to the left and right sides of the given length.

func (*String) PadLeft

func (s *String) PadLeft(length int, pad ...string) *String

PadLeft returns the String instance padded to the left side of the given length.

func (*String) PadRight

func (s *String) PadRight(length int, pad ...string) *String

PadRight returns the String instance padded to the right side of the given length.

func (*String) Pipe

func (s *String) Pipe(callback func(s string) string) *String

Pipe passes the string to the given callback and returns the result.

func (*String) Prepend

func (s *String) Prepend(values ...string) *String

Prepend one or more strings to the current string.

func (*String) RTrim

func (s *String) RTrim(characters ...string) *String

RTrim returns the String instance with the right occurrences of the given value removed.

func (*String) Remove

func (s *String) Remove(values ...string) *String

Remove returns the String instance with the first occurrence of the given value removed.

func (*String) Repeat

func (s *String) Repeat(times int) *String

Repeat returns the String instance repeated the given number of times.

func (*String) Replace

func (s *String) Replace(search string, replace string, caseSensitive ...bool) *String

Replace returns the String instance with all occurrences of the search string replaced by the given replacement string.

func (*String) ReplaceEnd

func (s *String) ReplaceEnd(search string, replace string) *String

ReplaceEnd returns the String instance with the last occurrence of the given value replaced.

func (*String) ReplaceFirst

func (s *String) ReplaceFirst(search string, replace string) *String

ReplaceFirst returns the String instance with the first occurrence of the given value replaced.

func (*String) ReplaceLast

func (s *String) ReplaceLast(search string, replace string) *String

ReplaceLast returns the String instance with the last occurrence of the given value replaced.

func (*String) ReplaceMatches

func (s *String) ReplaceMatches(pattern string, replace string) *String

ReplaceMatches returns the String instance with all occurrences of the given pattern replaced by the given replacement string.

func (*String) ReplaceStart

func (s *String) ReplaceStart(search string, replace string) *String

ReplaceStart returns the String instance with the first occurrence of the given value replaced.

func (*String) Snake

func (s *String) Snake(delimiter ...string) *String

Snake returns the String instance in snake case.

func (*String) Split

func (s *String) Split(pattern string, limit ...int) []string

Split splits the string by given pattern string.

func (*String) Squish

func (s *String) Squish() *String

Squish returns the String instance with consecutive whitespace characters collapsed into a single space.

func (*String) Start

func (s *String) Start(prefix string) *String

Start returns the String instance with the given value prepended.

func (*String) StartsWith

func (s *String) StartsWith(values ...string) bool

StartsWith returns true if the string starts with the given value or any of the values.

func (*String) String

func (s *String) String() string

String returns the string value.

func (*String) Studly

func (s *String) Studly() *String

Studly returns the String instance in studly case.

func (*String) Substr

func (s *String) Substr(start int, length ...int) *String

Substr returns the String instance starting at the given index with the specified length.

func (*String) Swap

func (s *String) Swap(replacements map[string]string) *String

Swap replaces all occurrences of the search string with the given replacement string.

func (*String) Tap

func (s *String) Tap(callback func(String)) *String

Tap passes the string to the given callback and returns the string.

func (*String) Test

func (s *String) Test(pattern string) bool

Test returns true if the string matches the given pattern.

func (*String) Title

func (s *String) Title() *String

Title returns the String instance in title case.

func (*String) Trim

func (s *String) Trim(characters ...string) *String

Trim returns the String instance with trimmed characters from the left and right sides.

func (*String) UcFirst

func (s *String) UcFirst() *String

UcFirst returns the String instance with the first character uppercased.

func (*String) UcSplit

func (s *String) UcSplit() []string

UcSplit splits the string into words using uppercase characters as the delimiter.

func (*String) Unless

func (s *String) Unless(callback func(*String) bool, fallback func(*String) *String) *String

Unless returns the String instance with the given fallback applied if the given condition is false.

func (*String) Upper

func (s *String) Upper() *String

Upper returns the String instance in upper case.

func (*String) When

func (s *String) When(condition bool, callback ...func(*String) *String) *String

When returns the String instance with the given callback applied if the given condition is true. If the condition is false, the fallback callback is applied.(if provided)

func (*String) WhenContains

func (s *String) WhenContains(value string, callback ...func(*String) *String) *String

WhenContains returns the String instance with the given callback applied if the string contains the given value.

func (*String) WhenContainsAll

func (s *String) WhenContainsAll(values []string, callback ...func(*String) *String) *String

WhenContainsAll returns the String instance with the given callback applied if the string contains all the given values.

func (*String) WhenEmpty

func (s *String) WhenEmpty(callback ...func(*String) *String) *String

WhenEmpty returns the String instance with the given callback applied if the string is empty.

func (*String) WhenEndsWith

func (s *String) WhenEndsWith(value []string, callback ...func(*String) *String) *String

WhenEndsWith returns the String instance with the given callback applied if the string ends with the given value.

func (*String) WhenExactly

func (s *String) WhenExactly(value string, callback ...func(*String) *String) *String

WhenExactly returns the String instance with the given callback applied if the string is exactly the given value.

func (*String) WhenIs

func (s *String) WhenIs(value string, callback ...func(*String) *String) *String

WhenIs returns the String instance with the given callback applied if the string matches any of the given patterns.

func (*String) WhenIsAscii

func (s *String) WhenIsAscii(callback ...func(*String) *String) *String

WhenIsAscii returns the String instance with the given callback applied if the string contains only ASCII characters.

func (*String) WhenIsUlid

func (s *String) WhenIsUlid(callback ...func(*String) *String) *String

WhenIsUlid returns the String instance with the given callback applied if the string is a valid ULID.

func (*String) WhenIsUuid

func (s *String) WhenIsUuid(callback ...func(*String) *String) *String

WhenIsUuid returns the String instance with the given callback applied if the string is a valid UUID.

func (*String) WhenNotEmpty

func (s *String) WhenNotEmpty(callback ...func(*String) *String) *String

WhenNotEmpty returns the String instance with the given callback applied if the string is not empty.

func (*String) WhenNotExactly

func (s *String) WhenNotExactly(value string, callback ...func(*String) *String) *String

WhenNotExactly returns the String instance with the given callback applied if the string is not exactly the given value.

func (*String) WhenStartsWith

func (s *String) WhenStartsWith(value []string, callback ...func(*String) *String) *String

WhenStartsWith returns the String instance with the given callback applied if the string starts with the given value.

func (*String) WhenTest

func (s *String) WhenTest(pattern string, callback ...func(*String) *String) *String

WhenTest returns the String instance with the given callback applied if the string matches the given pattern.

func (*String) WordCount

func (s *String) WordCount() int

WordCount returns the number of words in the string.

func (*String) Words

func (s *String) Words(limit int, end ...string) *String

Words return the String instance truncated to the given number of words.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL