caseconversion

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeCasePreservingSnakeCase

func EncodeCasePreservingSnakeCase(words DecodedIdentifier) string

EncodeCasePreservingSnakeCase encodes a slice of words into case_Preserving_snake_case

func EncodeKebabCase

func EncodeKebabCase(words DecodedIdentifier) string

EncodeKebabCase encodes a slice of words into kebab-case

func EncodeLowerCamelCase

func EncodeLowerCamelCase(words DecodedIdentifier) string

EncodeLowerCamelCase encodes a slice of words into lowerCamelCase

func EncodeLowerSnakeCase

func EncodeLowerSnakeCase(words DecodedIdentifier) string

EncodeLowerSnakeCase encodes a slice of words into lower_snake_case

func EncodeUpperCamelCase

func EncodeUpperCamelCase(words DecodedIdentifier) string

EncodeUpperCamelCase encodes a slice of words into UpperCamelCase

func EncodeUpperSnakeCase

func EncodeUpperSnakeCase(words DecodedIdentifier) string

EncodeUpperSnakeCase encodes a slice of words into UPPER_SNAKE_CASE (AKA SCREAMING_SNAKE_CASE)

Types

type DecodeCasingFunc

type DecodeCasingFunc func(string) (DecodedIdentifier, error)

DecodeCasingFunc takes in an identifier in a case such as camelCase or snake_case and splits it up into a DecodedIdentifier for encoding by an EncodeCasingFunc into a different case.

type DecodedIdentifier

type DecodedIdentifier []string

DecodedIdentifier is an slice of lowercase words (e.g., []string{"test", "string"}) produced by a DecodeCasingFunc, which can be encoded by an EncodeCasingFunc into a string in the specified case (e.g., with EncodeLowerCamelCase, "testString").

func DecodeCasePreservingSnakeCase

func DecodeCasePreservingSnakeCase(s string) (DecodedIdentifier, error)

DecodeCasePreservingSnakeCase decodes Case_Preserving_Snake_Case into a slice of lower-cased sub-string

func DecodeGoCamelCase

func DecodeGoCamelCase(s string) (DecodedIdentifier, error)

DecodeGoCamelCase decodes UpperCamelCase and lowerCamelCase strings with fully capitalized acronyms (e.g., "jsonAPIDocs") into a slice of lower-cased sub-strings.

func DecodeGoTags

func DecodeGoTags(s string) (DecodedIdentifier, error)

DecodeGoTags decodes CamelCase, snake_case, and kebab-case strings with fully capitalized acronyms into a slice of lower cased strings.

func DecodeKebabCase

func DecodeKebabCase(s string) (DecodedIdentifier, error)

DecodeKebabCase decodes kebab-case into a slice of lower-cased sub-strings

func DecodeLowerCamelCase

func DecodeLowerCamelCase(s string) (DecodedIdentifier, error)

DecodeLowerCamelCase decodes lowerCamelCase strings into a slice of lower-cased sub-strings

func DecodeLowerSnakeCase

func DecodeLowerSnakeCase(s string) (DecodedIdentifier, error)

DecodeLowerSnakeCase decodes lower_snake_case into a slice of lower-cased sub-strings

func DecodeUpperCamelCase

func DecodeUpperCamelCase(s string) (DecodedIdentifier, error)

DecodeUpperCamelCase decodes UpperCamelCase strings into a slice of lower-cased sub-strings

func DecodeUpperSnakeCase

func DecodeUpperSnakeCase(s string) (DecodedIdentifier, error)

DecodeUpperSnakeCase decodes UPPER_SNAKE_CASE (sometimes called SCREAMING_SNAKE_CASE) into a slice of lower-cased sub-strings

type EncodeCasingFunc

type EncodeCasingFunc func(DecodedIdentifier) string

EncodeCasingFunc combines the contents of a DecodedIdentifier into an identifier in a case such as camelCase or snake_case.

type GoCaseConverter added in v0.18.0

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

GoCaseConverter is a case converter that can decode and encode Go-style identifiers.

func NewGoCaseConverter added in v0.18.0

func NewGoCaseConverter() *GoCaseConverter

NewGoCaseConverter creates a new GoCaseConverter. Please see the `AddInitialism`, `SetInitialisms`, and `SetAtoms` methods for details on how to customize the encoding and decoding behavior.

func (*GoCaseConverter) AddInitialism added in v0.18.0

func (g *GoCaseConverter) AddInitialism(initialism ...string)

AddInitialisms adds the passed initialisms to the set of initialisms. Attempting to add an initialism less than two characters long will cause a panic. If any of the added initialisms duplicate any existing initialism, the duplicates will be silently ignored.

func (*GoCaseConverter) Decode added in v0.18.0

Decode implements DecodeCasingFunc for Go-style identifiers. It consults the internal list of initialisms and atoms to determine how to split the string.

func (*GoCaseConverter) DecodeGoTags added in v0.18.0

func (g *GoCaseConverter) DecodeGoTags(s string) (DecodedIdentifier, error)

DecodeGoTags decodes CamelCase, snake_case, and kebab-case strings with fully capitalized acronyms into a slice of lower cased strings.

func (*GoCaseConverter) Encode added in v0.18.0

func (g *GoCaseConverter) Encode(words DecodedIdentifier) string

Encode implements a EncodeCasingFunc for Go-style identifiers and returns an exported-style name (with an initial uppercase character).

func (*GoCaseConverter) EncodeUnexported added in v0.18.0

func (g *GoCaseConverter) EncodeUnexported(words DecodedIdentifier) string

EncodeUnexported is like Encode, but returns an unexported name (with an initial lowercase character) still adhering to the rules of initialisms and atoms.

func (*GoCaseConverter) SetAtoms added in v0.18.0

func (g *GoCaseConverter) SetAtoms(atoms []string)

SetAtoms sets the atoms used by the GoCaseConverter with the argument. If any atoms were previously set, SetAtoms replaces them. The set of atoms is initially empty, unlike the set of initialisms. Atoms will specifically not be split at word boundaries and should be provided in the exported-name format as in "ABTest". Attemping to add an atom less than two characters in length will cause a panic. Also, any duplicates in the list of atoms will be removed.

func (*GoCaseConverter) SetInitialisms added in v0.18.0

func (g *GoCaseConverter) SetInitialisms(initialisms []string)

SetInitialisms replaces the set of initialisms used by the GoCaseConverter with the argument. Attempting to set an initialism less than two characters long will cause a panic. Also, any duplicates in the list of initialisms will be silently discarded.

Jump to

Keyboard shortcuts

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