strcases

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: AGPL-3.0 Imports: 6 Imported by: 1

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func CGoField(field string) string

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 Dots

func Dots(parts ...string) string

Dots is a helper function to join strings in dots for debugging.

func FirstLetter

func FirstLetter(p string) string

FirstLetter returns the first letter in lower-case.

func Go

func Go(name string) string

Go converts either pascal or snake case to the Go name. The original casing is inferred from the given name.

func GuessSnake

func GuessSnake(name string) (snake bool)

GuessSnake guesses if the given name is snake-cased or not.

func Interfacify

func Interfacify(word string) string

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 IsLower

func IsLower(s string) bool

IsLower returns true if the string is all lower-cased.

func KebabToGo added in v0.0.2

func KebabToGo(pascal bool, kebabString string) string

KebabToGo converts kebab case to Go's special case. See SnakeToGo.

func PascalToGo

func PascalToGo(pascal string) string

PascalToGo converts regular Pascal case to Go.

func SetPascalWords

func SetPascalWords(words map[string]string)

SetPascalWords sets the given map of words to be replaced after the pascal specials stage as a method of fixing edge cases.

func SnakeNoGo

func SnakeNoGo(snake string) string

SnakeNoGo ensures the snake-case string is never a Go keyword.

func SnakeToGo

func SnakeToGo(pascal bool, snakeString string) string

SnakeToGo converts snake case to Go's special case. If Pascal is true, then the first letter is capitalized.

func UnexportPascal

func UnexportPascal(pascal string) string

UnexportPascal converts the PascalToGo string to be unexported.

Types

This section is empty.

Jump to

Keyboard shortcuts

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