goconvcase

package module
v0.0.0-...-1afbeaf Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: MIT Imports: 7 Imported by: 0

README

goconvcase Go

goconvcase transforms the case of an identifier.

image

Installation

go get github.com/kita127/goconvcase/cmd/goconvcase

Usage

usage: goconvcase.exe [<flags>] [<path>]

Flags:
      --help       Show context-sensitive help (also try --help-long and
                   --help-man).
  -w, --write      write result to (source) file instead of stdout
  -f, --from=FROM  from case
  -t, --to=TO      to case
  -l, --list       show valid cases

Args:
  [<path>]  go file path

e.g.) Convert upper snake case to upper camel case.

$cat examples\hoge.go
package hoge

import "fmt"

var (
        UPPER_SNAKE_VAR int
        lower_snake_var int
        UpperCamelVar   int
        lowerCamelVar   int
)

const (
        UPPER_SNAKE_CONST int = 0
        lower_snake_const int = 0
        UpperCamelConst   int = 0
        lowerCamelConst   int = 0
)

func UPPER_SNAKE_FUNC() {
        LOCAL_VAR := 0
        fmt.Println(LOCAL_VAR)
}

func lower_snake_func() {
        local_var := 0
        fmt.Println(local_var)
}

func UpperCamelFunc() {
        LocalVar := 0
        fmt.Println(LocalVar)
}

func lowerCamelFunc() {
        localVar := 0
        fmt.Println(localVar)
}

$goconvcase.exe --from us --to uc examples\hoge.go
package hoge

import "fmt"

var (
        UpperSnakeVar   int
        lower_snake_var int
        UpperCamelVar   int
        lowerCamelVar   int
)

const (
        UpperSnakeConst   int = 0
        lower_snake_const int = 0
        UpperCamelConst   int = 0
        lowerCamelConst   int = 0
)

func UpperSnakeFunc() {
        LocalVar := 0
        fmt.Println(LocalVar)
}

func lower_snake_func() {
        local_var := 0
        fmt.Println(local_var)
}

func UpperCamelFunc() {
        LocalVar := 0
        fmt.Println(LocalVar)
}

func lowerCamelFunc() {
        localVar := 0
        fmt.Println(localVar)
}

The valid cases are displayed with --list option.

$goconvcase.exe --list
us : UPPER_SNAKE_CASE like this.
uc : UpperCamelCase like this.
ls : lower_snake_case like this.
lc : lowerCamelCase like this.

Documentation

Index

Constants

View Source
const (
	UpperSnake = iota
	UpperCamel
	LowerSnake
	LowerCamel
)

case type values

Variables

This section is empty.

Functions

func ConvertCase

func ConvertCase(src string, from, to CaseType) (string, error)

ConvertCase function

Types

type Case

type Case interface {
	Decode(name string) *InterCode
	Encode(ic *InterCode) string
	IsThisCase(name string) bool
}

Case interface

type CaseType

type CaseType int

CaseType type

type Converter

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

Converter struct

func NewConverter

func NewConverter(from, to CaseType) *Converter

NewConverter function

func (*Converter) Convert

func (c *Converter) Convert(src string) (string, error)

Convert function

type InterCode

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

InterCode struct

type LCamel

type LCamel struct{}

LCamel struct

func (*LCamel) Decode

func (c *LCamel) Decode(name string) *InterCode

Decode *LCamel.Decode method

func (*LCamel) Encode

func (c *LCamel) Encode(ic *InterCode) string

Encode *LCamel.Encode method

func (*LCamel) IsThisCase

func (c *LCamel) IsThisCase(name string) bool

IsThisCase *LCamel.IsThisCase method

type LSnake

type LSnake struct{}

LSnake struct

func (*LSnake) Decode

func (c *LSnake) Decode(name string) *InterCode

Decode *LSnake.Decode method

func (*LSnake) Encode

func (c *LSnake) Encode(ic *InterCode) string

Encode *LSnake.Encode method

func (*LSnake) IsThisCase

func (c *LSnake) IsThisCase(name string) bool

IsThisCase *LSnake.IsThisCase method

type UCamel

type UCamel struct{}

UCamel struct

func (*UCamel) Decode

func (c *UCamel) Decode(name string) *InterCode

Decode *UCamel.Decode method

func (*UCamel) Encode

func (c *UCamel) Encode(ic *InterCode) string

Encode *UCamel.Encode method

func (*UCamel) IsThisCase

func (c *UCamel) IsThisCase(name string) bool

IsThisCase *UCamel.IsThisCase method

type USnake

type USnake struct{}

USnake struct

func (*USnake) Decode

func (c *USnake) Decode(name string) *InterCode

Decode *USnake.Decode method

func (*USnake) Encode

func (c *USnake) Encode(ic *InterCode) string

Encode *USnake.Encode method

func (*USnake) IsThisCase

func (c *USnake) IsThisCase(name string) bool

IsThisCase *USnake.IsThisCase method

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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