strings

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 6 Imported by: 26

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 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 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 SliceContains

func SliceContains(ss []string, s string) bool

SliceContains reports whether s is within ss.

func SliceUnique

func SliceUnique(i []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. "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.

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 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 "_".

Types

This section is empty.

Jump to

Keyboard shortcuts

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