strings

package
v1.2.117 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 7 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PascalCase           = UpperCamelCase
	CapitalizedWordsCase = UpperCamelCase
	CapWordsCase         = UpperCamelCase
	CapitalizedWords     = UpperCamelCase

	// SentenceCase is a mixed-case style in which the first word of the sentence is capitalised,
	// as well as proper nouns and other words as required by a more specific rule.
	// This is generally equivalent to the baseline universal standard of formal English orthography.
	// https://en.wikipedia.org/wiki/Letter_case#Sentence_Case
	// "The quick brown fox jumps over the lazy dog"
	SentenceCase = strings.Title

	// TitleCase capitalises all words but retains the spaces between them
	// https://en.wikipedia.org/wiki/Letter_case#Title_Case
	// "The Quick Brown Fox Jumps over the Lazy Dog"
	TitleCase = strings.ToTitle

	// AllCapsCase is an unicase style with capital letters only.
	// https://en.wikipedia.org/wiki/Letter_case#All_caps
	// "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
	AllCapsCase  = strings.ToUpper
	AllUpperCase = AllCapsCase

	// AllLowercase is an unicase style with no capital letters.
	// https://en.wikipedia.org/wiki/Letter_case#All_lowercase
	// "the quick brown fox jumps over the lazy dog"
	AllLowercase = strings.ToLower
)
View Source
var (
	DromedaryCase = LowerCamelCase
	// Some people and organizations, notably Microsoft, use the term camel case only for lower camel case.
	// Pascal case means only upper camel case.
	CamelCase = LowerCamelCase

	// MixedCase for lower camel case in Python
	MixedCase = LowerCamelCase
)
View Source
var (
	// lowercase
	LowerCase = strings.ToLower
)

Functions

func ComputePad

func ComputePad(s string, pad string, n int) (padCount, spaceCount int)

ComputePad returns pad's count and space's count(less than len(pad)) will be need to pad s to len n padCount = (n-len(s))/len(pad) spaceCount = (n-len(s))%len(pad)

func ContainsAnyRangeTable

func ContainsAnyRangeTable(s string, rangeTabs ...*unicode.RangeTable) bool

ContainsAnyRangeTable reports whether the string contains any rune in any of the specified table of ranges.

func ContainsAsciiVisual

func ContainsAsciiVisual(s string) bool

ContainsAsciiVisual reports whether the string contains any rune in visual ascii code, that is [0x21, 0x7E].

func ContainsOnlyAsciiVisual

func ContainsOnlyAsciiVisual(s string) bool

ContainsAsciiVisual reports whether the string contains only rune in visual ascii code, that is [0x21, 0x7E].

func ContainsOnlyRangeTable

func ContainsOnlyRangeTable(s string, rangeTabs ...*unicode.RangeTable) bool

ContainsOnlyRangeTable reports whether the string contains only rune in all of the specified table of ranges.

func ContainsRuneAnyFunc

func ContainsRuneAnyFunc(s string, f func(rune) bool) bool

ContainsRuneAnyFunc reports whether any of the Unicode code point r satisfying f(r) is within s.

func ContainsRuneOnlyFunc

func ContainsRuneOnlyFunc(s string, f func(rune) bool) bool

ContainsRuneOnlyFunc reports whether all of the Unicode code point r satisfying f(r) is within s.

func CountPrefix

func CountPrefix(s, substr string) int

CountPrefix counts the number of non-overlapping instances of continuous substr prefix in s. If substr is an empty string, CountPrefix returns 1 + the number of Unicode code points in s.

func CountSuffix

func CountSuffix(s, substr string) int

CountSuffix counts the number of non-overlapping instances of continuous substr suffix in s. If substr is an empty string, CountSuffix returns 1 + the number of Unicode code points in s.

func DarwinCase

func DarwinCase(s string, seps ...rune) string

DarwinCase returns the DarwinCased name. Darwin case uses underscores between words with initial uppercase letters, as in "Sample_Type" In short, _my_field_name_2 becomes X_My_Field_Name_2. see https://en.wikipedia.org/wiki/Camel_case

func DotCase

func DotCase(s string, seps ...rune) string

DotCase returns the KebabCased name. In short, _my_field_name_2 becomes x.my.field.name.2.

func DottedSlice

func DottedSlice(elem ...string) string

DottedSlice turns a sliced name into a dotted name.

func ExtractFirstRune

func ExtractFirstRune(s string) (rune, string)

func JoinGenerator

func JoinGenerator(sep string, mapping func(s string) string) func(r string) string

JoinGenerator supplies sep between strings step by step, with mapping if consists [r0,r1,r2] -> "r0'""sep""r1'""sep""r2'"

func JoinRepeat

func JoinRepeat(s string, sep string, n int) string

JoinRepeat behaves like strings.Join([]string{s,...,s}, sep)

func KebabCase

func KebabCase(s string, seps ...rune) string

KebabCase returns the KebabCased name. In short, _my_field_name_2 becomes x-my-field-name-2. "the-quick-brown-fox-jumps-over-the-lazy-dog"

func LowerCamelCase

func LowerCamelCase(s string, seps ...rune) string

LowerCamelCase returns the CamelCased name by lowercase uppercase letter. In short, _my_field_name_2 becomes xMyFieldName_2. "theQuickBrownFoxJumpsOverTheLazyDog"

func LowerCamelCaseSlice

func LowerCamelCaseSlice(elem ...string) string

LowerCamelCaseSlice is like LowerCamelCase, but the argument is a slice of strings to be joined with "_".

func LowerCaseWithUnderscores

func LowerCaseWithUnderscores(s string, seps ...rune) string

lower_case_with_underscores

func MapLeading

func MapLeading(mapping func(rune) rune, s string) string

MapLeading returns a copy of the string s with its first characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the string with no replacement.

func PadLeft

func PadLeft(s string, pad string, n int) string

PadLeft returns s padded to length n, padded left with repeated pad return s directly if pad is empty padding s with {{pad}} and spaces(less than len(pad)) as a prefix, as [pad]...[pad][space]...[space][s]

func PadRight

func PadRight(s string, pad string, n int) string

PadRight returns s padded to length n, padded right with repeated pad return s directly if pad is empty padding s with {{pad}} and spaces(less than len(pad)) as a suffix, as [s][space]...[space][pad]...[pad]

func ReverseByByte

func ReverseByByte(s string) string

ReverseByByte returns a string with the bytes of s in reverse order.

func ReverseByRune

func ReverseByRune(s string) string

ReverseByRune returns a string with the runes of s in reverse order. Invalid UTF-8 sequences, if any, will be reversed byte by byte.

func SliceCombine

func SliceCombine(ss ...[]string) []string

SliceCombine combine elements to a new slice.

func SliceContains

func SliceContains(ss []string, tt ...string) bool

SliceContains reports whether all t in tt is within ss.

func SliceContainsAny

func SliceContainsAny(ss []string, tt ...string) bool

SliceContainsAny reports whether any t in tt is within ss.

func SliceEqual

func SliceEqual(s, t []string) bool

SliceEqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-sensitivity.

func SliceEqualFold

func SliceEqualFold(s, t []string) bool

SliceEqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-insensitivity.

func SliceTrim

func SliceTrim(ss []string, tt ...string) []string

SliceTrim returns a slice of the string ss with tt removed.

func SliceTrimEmpty

func SliceTrimEmpty(ss ...string) []string

SliceTrimEmpty trim empty columns

func SliceTrimFunc

func SliceTrimFunc(ss []string, f func(s string) bool) []string

SliceTrimFunc returns a slice of the string ss satisfying f(c) removed.

func SliceUnique

func SliceUnique(s ...string) []string

SliceUnique returns the given string slice with unique values.

func SnakeCase

func SnakeCase(s string, seps ...rune) string

SnakeCase returns the SnakeCased name. In short, _my_field_name_2 becomes x_my_field_name_2. seps will append '_' if len(seps) == 0 "the_quick_brown_fox_jumps_over_the_lazy_dog"

func SplitPrefixNumber

func SplitPrefixNumber(s string) []string

SplitPrefixNumber slices s into number prefix and unparsed and returns a slice of those substrings. If s does not start with number, SplitPrefixNumber returns a slice of length 1 whose only element is s. If s is with number only, SplitPrefixNumber returns a slice of length 1 whose only element is s.

func StudlyCapsCase

func StudlyCapsCase(upperCase unicode.SpecialCase, s string) string

Studly caps is a form of text notation in which the capitalization of letters varies by some pattern, or arbitrarily, usually also omitting spaces between words and often omitting some letters, for example, StUdLyCaPs or STuDLyCaPS. Such patterns are identified by many users, ambiguously, as camel case. The typical alternative is to just replace spaces with underscores (as in snake case). Messages may be hidden in the capital and lower-case letters such as "ShoEboX" which spells "SEX" in capitals and "hobo" in lower-case. https://en.wikipedia.org/wiki/Studly_caps "tHeqUicKBrOWnFoXJUmpsoVeRThElAzydOG" "THiS iS aN eXCePTioNaLLy eLiTe SeNTeNCe"

func StudlyCapsConsonantUpperCase

func StudlyCapsConsonantUpperCase(s string) string

"THeQuiCKBRoWNFoXJuMPSoVeRTHeLaZYDoG"

func StudlyCapsVowelUpperCase

func StudlyCapsVowelUpperCase(s string) string

"thEqUIckbrOwnfOxjUmpsOvErthElAzydOg"

func ToLowerLeading

func ToLowerLeading(s string) string

ToLowerLeading returns s with it's first Unicode letter mapped to their lower case.

func ToUpperLeading

func ToUpperLeading(s string) string

ToUpperLeading returns s with it's first Unicode letter mapped to their upper case.

func TransformCase

func TransformCase(s string, join func(r string) string, seps ...rune) string

TransformCase Splits and apply map on every splits

func TrimPrefixComplex

func TrimPrefixComplex(s string) string

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

func TrimPrefixFloat

func TrimPrefixFloat(s string) string

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

func TrimPrefixInteger

func TrimPrefixInteger(s string) string

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

func TrimPrefixNumber

func TrimPrefixNumber(s string) string

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

func Truncate

func Truncate(s string, n int) string

Truncate shrinks s's len to n at most

func UpperCamelCase

func UpperCamelCase(s string, seps ...rune) string

UpperCamelCase returns the CamelCased name by initial uppercase letter. If there is an interior split rune such as an underscore followed by a lower case letter, drop the underscore and convert the letter to upper case. There is a remote possibility of this rewrite causing a name collision, but it's so remote we're prepared to pretend it's nonexistent - since the C++ JoinGenerator lowercases names, it's extremely unlikely to have two fields with different capitalizations. In short, _my_field_name_2 becomes XMyFieldName_2. "TheQuickBrownFoxJumpsOverTheLazyDog"

func UpperCamelCaseSlice

func UpperCamelCaseSlice(elem ...string) string

UpperCamelCaseSlice is like UpperCamelCase, but the argument is a slice of strings to be joined with "_".

func ValueOrDefault

func ValueOrDefault(values ...string) string

ValueOrDefault Return first value nonempty Example:

ValueOrDefault(value, def)

Types

This section is empty.

Jump to

Keyboard shortcuts

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