gid

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: MIT Imports: 2 Imported by: 0

README

gid

gid is a small lib to convert a string to a valid Go identifier.

build

TLDR;

import "github.com/MartyHub/gid"

tok := gid.Default()

tok.ExportID("id") // ID 
tok.ExportID("my_id") // MyID 
tok.ExportID("json_id") // JSONId

tok.UnexportID("ID") // id 
tok.UnexportID("my_id") // myID 
tok.UnexportID("json_id") // jsonID

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capitalize

func Capitalize(s string) string

Types

type Option

type Option func(Tokenizer)

func WithDefaultReplacements

func WithDefaultReplacements() Option

func WithDefaultReserved

func WithDefaultReserved() Option

func WithReplacement

func WithReplacement(s string) Option

func WithReserved

func WithReserved(s string) Option

type Token

type Token struct {
	Class TokenClass
	Runes []rune
}

func NewToken

func NewToken(class TokenClass, r ...rune) *Token

func (*Token) Append

func (tok *Token) Append(r rune)

func (*Token) Pop

func (tok *Token) Pop() rune

func (*Token) Valid

func (tok *Token) Valid() bool

type TokenClass

type TokenClass int
const (
	ClassOther TokenClass = iota
	ClassLowerCase
	ClassUpperCase
	ClassDigit
)

type Tokenizer

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

func Default

func Default() Tokenizer

func New

func New(opts ...Option) Tokenizer

func (Tokenizer) ExportID

func (tokenizer Tokenizer) ExportID(s string) string

func (Tokenizer) ToCamel

func (tokenizer Tokenizer) ToCamel(s string, export bool) string

func (Tokenizer) Tokens

func (tokenizer Tokenizer) Tokens(s string) []*Token

func (Tokenizer) UnexportID

func (tokenizer Tokenizer) UnexportID(s string) string

Jump to

Keyboard shortcuts

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