stringx

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: MIT Imports: 6 Imported by: 19

Documentation

Index

Constants

View Source
const LineBreak = "\n"

LineBreak indicates the value to use as line break

Variables

This section is empty.

Functions

func CamelToDash

func CamelToDash(s string) string

CamelToDash converts CamelCase to dash-separated-string

func CamelToSnake

func CamelToSnake(s string) string

CamelToSnake converts CamelCase to snake_case.

func DashToCamel

func DashToCamel(s string) string

DashToCamel converts a dash-separated-string to CamelCase

func DashToPascal

func DashToPascal(s string) string

DashToCamel converts a dash-separated-string to CamelCase

func GetOrDefault

func GetOrDefault(def string, args ...string) string

GetOrDefault is a helper for variadic arguments when used as single optional input value in a variadic function.

func PascalToDash

func PascalToDash(s string) string

func PascalToSnake

func PascalToSnake(s string) string

CamelToSnake converts CamelCase to snake_case.

func SnakeToCamel

func SnakeToCamel(s string) string

SnakeToCamel converts snake_case to CamelCase

func SnakeToPascal

func SnakeToPascal(s string) string

SnakeToCamel converts snake_case to CamelCase

func ToTitle added in v1.0.3

func ToTitle(s string) string

ToTitle converts the provided space separated string into a title case string, ensuring the string is all lowercase but capitalizing the first letter of every word

Types

type String

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

func Join

func Join(a []string, sep string) String

func New

func New(str string) String

func (String) Contains

func (s String) Contains(substr string) bool

Contains reports whether substr is within s.

func (String) ContainsAny

func (s String) ContainsAny(chars string) bool

ContainsAny reports whether any Unicode code points in chars are within s.

func (String) ContainsRune

func (s String) ContainsRune(r rune) bool

ContainsRune reports whether the Unicode code point r is within s.

func (String) Count

func (s String) Count(sep string) int

Count counts the number of non-overlapping instances of sep in s. If sep is an empty string, Count returns 1 + the number of Unicode code points in s.

func (String) EqualFold

func (s String) EqualFold(t string) bool

EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding.

func (String) Fields

func (s String) Fields() []string

Fields splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning an array of substrings of s or an empty list if s contains only white space.

func (String) FieldsFunc

func (s String) FieldsFunc(f func(rune) bool) []string

FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s. If all code points in s satisfy f(c) or the string is empty, an empty slice is returned. FieldsFunc makes no guarantees about the order in which it calls f(c). If f does not return consistent results for a given c, FieldsFunc may crash.

func (String) HasPrefix

func (s String) HasPrefix(prefix string) bool

HasPrefix tests whether the string s begins with prefix.

func (String) HasSuffix

func (s String) HasSuffix(suffix string) bool

HasSuffix tests whether the string s ends with suffix.

func (String) Index

func (s String) Index(sep string) int

Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.

func (String) IndexAny

func (s String) IndexAny(chars string) int

IndexAny returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

func (String) IndexByte

func (s String) IndexByte(c byte) int

IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.

func (String) IndexFunc

func (s String) IndexFunc(f func(rune) bool) int

IndexFunc returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do.

func (String) IndexRune

func (s String) IndexRune(r rune) int

IndexRune returns the index of the first instance of the Unicode code point r, or -1 if rune is not present in s. If r is utf8.RuneError, it returns the first instance of any invalid UTF-8 byte sequence.

func (String) LastIndex

func (s String) LastIndex(sep string) int

LastIndex returns the index of the last instance of sep in s, or -1 if sep is not present in s.

func (String) LastIndexAny

func (s String) LastIndexAny(chars string) int

LastIndexAny returns the index of the last instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

func (String) LastIndexByte

func (s String) LastIndexByte(c byte) int

LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.

func (String) LastIndexFunc

func (s String) LastIndexFunc(f func(rune) bool) int

LastIndexFunc returns the index into s of the last Unicode code point satisfying f(c), or -1 if none do.

func (String) Map

func (s String) Map(mapping func(rune) rune) String

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 (String) NewReader

func (s String) NewReader() *strings.Reader

NewReader returns a new Reader reading from s. It is similar to bytes.NewBufferString but more efficient and read-only.

func (String) Repeat

func (s String) Repeat(count int) String

Repeat returns a new string consisting of count copies of the string s.

It panics if count is negative or if the result of (len(s) * count) overflows.

func (String) Replace

func (s String) Replace(old, new string, n int) String

Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new.

func (String) S

func (s String) S() string

S returns the current state of the string

func (String) Split

func (s String) Split(sep string) []string

Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators. If sep is empty, Split splits after each UTF-8 sequence. It is equivalent to SplitN with a count of -1.

func (String) SplitAfter

func (s String) SplitAfter(sep string) []string

SplitAfter slices s into all substrings after each instance of sep and returns a slice of those substrings. If sep is empty, SplitAfter splits after each UTF-8 sequence. It is equivalent to SplitAfterN with a count of -1.

func (String) SplitAfterN

func (s String) SplitAfterN(sep string, n int) []string

SplitAfterN slices s into substrings after each instance of sep and returns a slice of those substrings. If sep is empty, SplitAfterN splits after each UTF-8 sequence. The count determines the number of substrings to return:

n > 0: at most n substrings; the last substring will be the unsplit remainder.
n == 0: the result is nil (zero substrings)
n < 0: all substrings

func (String) SplitN

func (s String) SplitN(sep string, n int) []string

SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators. If sep is empty, SplitN splits after each UTF-8 sequence. The count determines the number of substrings to return:

n > 0: at most n substrings; the last substring will be the unsplit remainder.
n == 0: the result is nil (zero substrings)
n < 0: all substrings

func (String) Title

func (s String) Title() String

Title returns a copy of the string s with all Unicode letters that begin words mapped to their title case.

BUG(rsc): The rule Title uses for word boundaries does not handle Unicode punctuation properly.

func (String) ToLower

func (s String) ToLower() String

ToLower returns a copy of the string s with all Unicode letters mapped to their lower case.

func (String) ToLowerSpecial

func (s String) ToLowerSpecial(c unicode.SpecialCase) String

ToLowerSpecial returns a copy of the string s with all Unicode letters mapped to their lower case, giving priority to the special casing rules.

func (String) ToTitle

func (s String) ToTitle() String

ToTitle returns a copy of the string s with all Unicode letters mapped to their title case.

func (String) ToTitleSpecial

func (s String) ToTitleSpecial(c unicode.SpecialCase) String

ToTitleSpecial returns a copy of the string s with all Unicode letters mapped to their title case, giving priority to the special casing rules.

func (String) ToUpper

func (s String) ToUpper() String

ToUpper returns a copy of the string s with all Unicode letters mapped to their upper case.

func (String) ToUpperSpecial

func (s String) ToUpperSpecial(c unicode.SpecialCase) String

ToUpperSpecial returns a copy of the string s with all Unicode letters mapped to their upper case, giving priority to the special casing rules.

func (String) Trim

func (s String) Trim(cutset string) String

Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.

func (String) TrimLeft

func (s String) TrimLeft(cutset string) String

TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.

func (String) TrimPrefix

func (s String) TrimPrefix(prefix string) String

TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.

func (String) TrimRight

func (s String) TrimRight(cutset string) String

TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.

func (String) TrimSpace

func (s String) TrimSpace() String

TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

func (String) TrimSuffix

func (s String) TrimSuffix(suffix string) String

TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.

type StringBuilder

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

StringBuilder encapsulates the buffer to use for the builder

func Builder

func Builder() *StringBuilder

Builder Creates a new StringBuilder

func (*StringBuilder) Append

func (s *StringBuilder) Append(args ...string) *StringBuilder

Append Appends the given string(s) to the builder

func (*StringBuilder) AppendInt

func (s *StringBuilder) AppendInt(i ...int) *StringBuilder

AppendInt Appends the given number(s) to the builder

func (*StringBuilder) AppendLine

func (s *StringBuilder) AppendLine(lines ...string) *StringBuilder

AppendLine Appends the given string(s) to the builder.

func (*StringBuilder) AppendLinef

func (s *StringBuilder) AppendLinef(format string, args ...interface{}) *StringBuilder

AppendLinef processes a string format based on the format and arguments passed, appends the result to the builder and a new line at the end

func (*StringBuilder) AppendObj

func (s *StringBuilder) AppendObj(objs ...interface{}) *StringBuilder

AppendObj attempts to obtain a string representation of the interface{} (s) and appends it/them to the builder

func (*StringBuilder) AppendRune

func (s *StringBuilder) AppendRune(char rune) *StringBuilder

AppendRune Appends a single character to the builder

func (*StringBuilder) Appendf

func (s *StringBuilder) Appendf(format string, args ...interface{}) *StringBuilder

Appendf processes a string format based on the format and arguments passed and appends the result to the builder

func (*StringBuilder) Br

func (s *StringBuilder) Br() *StringBuilder

Br Breaks to the next line

func (*StringBuilder) Build

func (s *StringBuilder) Build() string

Build Builds the string

func (*StringBuilder) IsEmpty

func (s *StringBuilder) IsEmpty() bool

IsEmpty Indicates whether the builder is empty

Notes

Bugs

  • The rule Title uses for word boundaries does not handle Unicode punctuation properly.

Jump to

Keyboard shortcuts

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