str

package
v1.13.8 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 12 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Camel2Case added in v1.0.0

func Camel2Case(name string) string

func Case2Camel added in v1.0.0

func Case2Camel(name string) string

func Random

func Random(length int) string

func Substr added in v1.13.2

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 added in v1.0.0

type Buffer struct {
	*bytes.Buffer
}

func NewBuffer added in v1.0.0

func NewBuffer() *Buffer

func (*Buffer) Append added in v1.0.0

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

type ExcerptOption added in v1.13.2

type ExcerptOption struct {
	Radius   int
	Omission string
}

ExcerptOption is the option for Excerpt method

type String added in v1.13.2

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

func Of added in v1.13.2

func Of(value string) *String

Of creates a new String instance with the given value.

func (*String) After added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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

Append appends one or more strings to the current string.

func (*String) Basename added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

func (s *String) Camel() *String

Camel returns the String instance in camel case.

func (*String) CharAt added in v1.13.2

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

CharAt returns the character at the specified index.

func (*String) Contains added in v1.13.2

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 added in v1.13.2

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

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

func (*String) Dirname added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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

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

func (*String) Excerpt added in v1.13.2

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

Excerpt returns the String instance truncated to the given length.

func (*String) Explode added in v1.13.2

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

Explode splits the string by given delimiter string.

func (*String) Finish added in v1.13.2

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 added in v1.13.2

func (s *String) Headline() *String

Headline returns the String instance in headline case.

func (*String) Is added in v1.13.2

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

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

func (*String) IsAscii added in v1.13.2

func (s *String) IsAscii() bool

IsAscii returns true if the string contains only ASCII characters.

func (*String) IsEmpty added in v1.13.2

func (s *String) IsEmpty() bool

IsEmpty returns true if the string is empty.

func (*String) IsMap added in v1.13.2

func (s *String) IsMap() bool

IsMap returns true if the string is a valid Map.

func (*String) IsMatch added in v1.13.2

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

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

func (*String) IsNotEmpty added in v1.13.2

func (s *String) IsNotEmpty() bool

IsNotEmpty returns true if the string is not empty.

func (*String) IsSlice added in v1.13.2

func (s *String) IsSlice() bool

IsSlice returns true if the string is a valid Slice.

func (*String) IsUlid added in v1.13.2

func (s *String) IsUlid() bool

IsUlid returns true if the string is a valid ULID.

func (*String) IsUuid added in v1.13.2

func (s *String) IsUuid() bool

IsUuid returns true if the string is a valid UUID.

func (*String) Kebab added in v1.13.2

func (s *String) Kebab() *String

Kebab returns the String instance in kebab case.

func (*String) LTrim added in v1.13.2

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

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

func (*String) LcFirst added in v1.13.2

func (s *String) LcFirst() *String

LcFirst returns the String instance with the first character lowercased.

func (*String) Length added in v1.13.2

func (s *String) Length() int

Length returns the length of the string.

func (*String) Limit added in v1.13.2

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

Limit returns the String instance truncated to the given length.

func (*String) Lower added in v1.13.2

func (s *String) Lower() *String

Lower returns the String instance in lower case.

func (*String) Mask added in v1.13.2

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 added in v1.13.2

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

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

func (*String) MatchAll added in v1.13.2

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

MatchAll returns all matches for the given regular expression.

func (*String) NewLine added in v1.13.2

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

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

func (*String) PadBoth added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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

Prepend one or more strings to the current string.

func (*String) RTrim added in v1.13.2

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

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

func (*String) Remove added in v1.13.2

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

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

func (*String) Repeat added in v1.13.2

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

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

func (*String) Replace added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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

Snake returns the String instance in snake case.

func (*String) Split added in v1.13.2

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

Split splits the string by given pattern string.

func (*String) Squish added in v1.13.2

func (s *String) Squish() *String

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

func (*String) Start added in v1.13.2

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

Start returns the String instance with the given value prepended.

func (*String) StartsWith added in v1.13.2

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 added in v1.13.2

func (s *String) String() string

String returns the string value.

func (*String) Studly added in v1.13.2

func (s *String) Studly() *String

Studly returns the String instance in studly case.

func (*String) Substr added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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

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

func (*String) Test added in v1.13.2

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

Test returns true if the string matches the given pattern.

func (*String) Title added in v1.13.2

func (s *String) Title() *String

Title returns the String instance in title case.

func (*String) Trim added in v1.13.2

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

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

func (*String) UcFirst added in v1.13.2

func (s *String) UcFirst() *String

UcFirst returns the String instance with the first character uppercased.

func (*String) UcSplit added in v1.13.2

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

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

func (*String) Unless added in v1.13.2

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 added in v1.13.2

func (s *String) Upper() *String

Upper returns the String instance in upper case.

func (*String) When added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

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 added in v1.13.2

func (s *String) WordCount() int

WordCount returns the number of words in the string.

func (*String) Words added in v1.13.2

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