Documentation ¶
Overview ¶
Package strcases provides helper functions to convert between string cases, such as Pascal Case, snake_case and Go's Mixed Caps, along with various special cases.
Index ¶
- Variables
- func AddPascalSpecials(regexes []string)
- func CGoField(field string) string
- func Dots(parts ...string) string
- func FirstLetter(p string) string
- func Go(name string) string
- func GuessSnake(name string) (snake bool)
- func Interfacify(word string) string
- func IsLower(s string) bool
- func KebabToGo(pascal bool, kebabString string) string
- func PascalToGo(pascal string) string
- func SetPascalWords(words map[string]string)
- func SnakeNoGo(snake string) string
- func SnakeToGo(pascal bool, snakeString string) string
- func UnexportPascal(pascal string) string
Constants ¶
This section is empty.
Variables ¶
var GoBuiltinTypes = map[string]string{
"bool": "",
"byte": "",
"complex128": "cmplx",
"complex64": "cmplx",
"error": "err",
"float32": "",
"float64": "",
"int": "",
"int16": "",
"int32": "",
"int64": "",
"int8": "",
"rune": "",
"string": "str",
"uint": "",
"uint16": "",
"uint32": "",
"uint64": "",
"uint8": "",
"uintptr": "",
}
GoBuiltinTypes contains Go built-in types.
var GoKeywords = map[string]string{
"break": "",
"default": "",
"func": "fn",
"interface": "iface",
"select": "sel",
"case": "",
"defer": "",
"go": "",
"map": "",
"struct": "",
"chan": "ch",
"else": "",
"goto": "",
"package": "pkg",
"switch": "",
"const": "",
"fallthrough": "",
"if": "",
"range": "",
"type": "typ",
"continue": "",
"for": "",
"import": "",
"return": "ret",
"var": "",
}
GoKeywords includes Go keywords. This is primarily to prevent collisions with meaningful Go words.
Functions ¶
func AddPascalSpecials ¶
func AddPascalSpecials(regexes []string)
AddPascalSpecials adds the given list of regexes into the list of cases that will be fully capitalized during case conversion to Go.
func CGoField ¶
CGoField formats the C field name to not be confused with a Go keyword. See https://golang.org/cmd/cgo/#hdr-Go_references_to_C.
func FirstLetter ¶
FirstLetter returns the first letter in lower-case.
func Go ¶
Go converts either pascal or snake case to the Go name. The original casing is inferred from the given name.
func GuessSnake ¶
GuessSnake guesses if the given name is snake-cased or not.
func Interfacify ¶
Interfacify appends the -er suffix into the given word to idiomatically adhere to Go's interface naming convention. If the word already ends with an -er suffix, then another suffix will be added.
func PascalToGo ¶
PascalToGo converts regular Pascal case to Go.
func SetPascalWords ¶
SetPascalWords sets the given map of words to be replaced after the pascal specials stage as a method of fixing edge cases.
func SnakeToGo ¶
SnakeToGo converts snake case to Go's special case. If Pascal is true, then the first letter is capitalized.
func UnexportPascal ¶
UnexportPascal converts the PascalToGo string to be unexported.
Types ¶
This section is empty.