Documentation
¶
Overview ¶
This library provides some functions that convert string cases between camelCase, COBOL-CASE, kebab-case, MACRO_CASE, PascalCase, snake_case and Train-Case.
Basically, these functions targets the upper and lower cases of only ASCII alphabets for capitalization, and all characters except ASCII alphabets and ASCII numbers are eliminated as word separators.
To limit characters using as separators, the functions named like *_with_sep are provided, and to keep specified characters, the functions named like *_with_keep are provided.
Index ¶
- func CamelCase(input string) string
- func CamelCaseWithKeep(input, keeped string) string
- func CamelCaseWithSep(input, seps string) string
- func CobolCase(input string) string
- func CobolCaseWithKeep(input, keeped string) string
- func CobolCaseWithSep(input, seps string) string
- func KebabCase(input string) string
- func KebabCaseWithKeep(input, keeped string) string
- func KebabCaseWithSep(input, seps string) string
- func MacroCase(input string) string
- func MacroCaseWithKeep(input, keeped string) string
- func MacroCaseWithSep(input, seps string) string
- func PascalCase(input string) string
- func PascalCaseWithKeep(input, keeped string) string
- func PascalCaseWithSep(input, seps string) string
- func SnakeCase(input string) string
- func SnakeCaseWithKeep(input, keeped string) string
- func SnakeCaseWithSep(input, seps string) string
- func TrainCase(input string) string
- func TrainCaseWithKeep(input, keeped string) string
- func TrainCaseWithSep(input, seps string) string
Examples ¶
- CamelCase
- CamelCaseWithKeep
- CamelCaseWithSep
- CobolCase
- CobolCaseWithKeep
- CobolCaseWithSep
- KebabCase
- KebabCaseWithKeep
- KebabCaseWithSep
- MacroCase
- MacroCaseWithKeep
- MacroCaseWithSep
- PascalCase
- PascalCaseWithKeep
- PascalCaseWithSep
- SnakeCase
- SnakeCaseWithKeep
- SnakeCaseWithSep
- TrainCase
- TrainCaseWithKeep
- TrainCaseWithSep
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelCase ¶
Converts a string to camel case.
This function takes a string as its argument, then returns a string of which the case style is camel case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and all characters except ASII alphabets and ASII numbers are eliminated as word separators.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
camel := stringcase.CamelCase("foo_bar_baz")
fmt.Printf("camel = %s\n", camel)
}
Output: camel = fooBarBaz
func CamelCaseWithKeep ¶
Converts a string to camel case using characters other than the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is camel case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters other than the specified characters as the second argument of this function are regarded as word separators and are eliminated.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
camel := stringcase.CamelCaseWithKeep("foo-bar100%baz", "%")
fmt.Printf("camel = %s\n", camel)
}
Output: camel = fooBar100%Baz
func CamelCaseWithSep ¶
Converts a string to camel case using the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is camel case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters specified as the second argument of this function are regarded as word separators and are eliminated.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
camel := stringcase.CamelCaseWithSep("foo-bar100%baz", "- ")
fmt.Printf("camel = %s\n", camel)
}
Output: camel = fooBar100%Baz
func CobolCase ¶
Converts a string to cobol case.
This function takes a string as its argument, then returns a string of which the case style is cobol case.
This function targets the upper and lower cases of ASCII alphabets for capitalization, and all characters except ASCII alphabets and ASCII numbers are replaced to hyphens as word separators.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
cobol := stringcase.CobolCase("foo_bar_baz")
fmt.Printf("cobol = %s\n", cobol)
}
Output: cobol = FOO-BAR-BAZ
func CobolCaseWithKeep ¶
Converts a string to cobol case using characters other than the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is cobol case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters other than the specified characters as the second argument of this function are regarded as word separators and are replaced to hyphens.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
cobol := stringcase.CobolCaseWithKeep("foo-bar100%baz", "%")
fmt.Printf("cobol = %s\n", cobol)
}
Output: cobol = FOO-BAR100%-BAZ
func CobolCaseWithSep ¶
Converts a string to cobol case using the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is cobol case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters specified as the second argument of this function are regarded as word separators and are replaced to hyphens.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
cobol := stringcase.CobolCaseWithSep("foo-bar100%baz", "- ")
fmt.Printf("cobol = %s\n", cobol)
}
Output: cobol = FOO-BAR100%-BAZ
func KebabCase ¶
Converts a string to kebab case.
This function takes a string as its argument, then returns a string of which the case style is kebab case.
This function targets the upper and lower cases of ASCII alphabets for capitalization, and all characters except ASCII alphabets and ASCII numbers are eliminated as word separators.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
kebab := stringcase.KebabCase("fooBarBaz")
fmt.Printf("kebab = %s\n", kebab)
}
Output: kebab = foo-bar-baz
func KebabCaseWithKeep ¶
Converts a string to kebab case using characters other than the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is kebab case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters other than the specified characters as the second argument of this function are regarded as word separators and are replaced to hyphens.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
kebab := stringcase.KebabCaseWithKeep("foo-bar100%baz", "%")
fmt.Printf("kebab = %s\n", kebab)
}
Output: kebab = foo-bar100%-baz
func KebabCaseWithSep ¶
Converts a string to kebab case using the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is kebab case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters specified as the second argument of this function are regarded as word separators and are replaced to hyphens.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
kebab := stringcase.KebabCaseWithSep("foo-bar100%baz", "- ")
fmt.Printf("kebab = %s\n", kebab)
}
Output: kebab = foo-bar100%-baz
func MacroCase ¶
Converts a string to macro case.
This function takes a string as its argument, then returns a string of which the case style is macro case.
This function targets the upper and lower cases of ASCII alphabets for capitalization, and all characters except ASCII alphabets and ASCII numbers are eliminated as word separators.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
macro := stringcase.MacroCase("fooBarBaz")
fmt.Printf("macro = %s\n", macro)
}
Output: macro = FOO_BAR_BAZ
func MacroCaseWithKeep ¶
Converts a string to macro case using characters other than the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is macro case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters other than the specified characters as the second argument of this function are regarded as word separators and are replaced to underscores.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
macro := stringcase.MacroCaseWithKeep("foo-Bar100%Baz", "%")
fmt.Printf("macro = %s\n", macro)
}
Output: macro = FOO_BAR100%_BAZ
func MacroCaseWithSep ¶
Converts a string to macro case using the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is macro case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters specified as the second argument of this function are regarded as word separators and are replaced to underscores.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
macro := stringcase.MacroCaseWithSep("foo-Bar100%Baz", "- ")
fmt.Printf("macro = %s\n", macro)
}
Output: macro = FOO_BAR100%_BAZ
func PascalCase ¶
Converts a string to pascal case.
This function takes a string as its argument, then returns a string of which the case style is pascal case.
This function targets the upper and lower cases of ASCII alphabets for capitalization, and all characters except ASCII alphabets and ASCII numbers are eliminated as word separators.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
pascal := stringcase.PascalCase("foo_bar_baz")
fmt.Printf("pascal = %s\n", pascal)
}
Output: pascal = FooBarBaz
func PascalCaseWithKeep ¶
Converts a string to pascal case using the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is pascal case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters specified as the second argument of this function are regarded as word separators and are eliminated.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
pascal := stringcase.PascalCaseWithKeep("foo-bar100%baz", "%")
fmt.Printf("pascal = %s\n", pascal)
}
Output: pascal = FooBar100%Baz
func PascalCaseWithSep ¶
Converts a string to pascal case using the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is pascal case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters specified as the second argument of this function are regarded as word separators and are eliminated.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
pascal := stringcase.PascalCaseWithSep("foo-Bar100%Baz", "- ")
fmt.Printf("pascal = %s\n", pascal)
}
Output: pascal = FooBar100%Baz
func SnakeCase ¶
Converts a string to snake case.
This function takes a string as its argument, then returns a string of which the case style is snake case.
This function targets the upper and lower cases of ASCII alphabets for capitalization, and all characters except ASCII alphabets and ASCII numbers are eliminated as word separators.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
snake := stringcase.SnakeCase("fooBarBaz")
fmt.Printf("snake = %s\n", snake)
}
Output: snake = foo_bar_baz
func SnakeCaseWithKeep ¶
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
snake := stringcase.SnakeCaseWithKeep("foo-bar100%baz", "%")
fmt.Printf("snake = %s\n", snake)
}
Output: snake = foo_bar100%_baz
func SnakeCaseWithSep ¶
Converts a string to snake case using the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is snake case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters specified as the second argument of this function are regarded as word separators and are replaced to underscores.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
snake := stringcase.SnakeCaseWithSep("foo-Bar100%Baz", "- ")
fmt.Printf("snake = %s\n", snake)
}
Output: snake = foo_bar100%_baz
func TrainCase ¶
Converts a string to train case.
This function takes a string as its argument, then returns a string of which the case style is train case.
This function targets the upper and lower cases of ASCII alphabets for capitalization, and all characters except ASCII alphabets and ASCII numbers are eliminated as word separators.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
train := stringcase.TrainCase("fooBarBaz")
fmt.Printf("train = %s\n", train)
}
Output: train = Foo-Bar-Baz
func TrainCaseWithKeep ¶
Converts a string to train case using characters other than the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is train case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters other than the specified characters as the second argument of this function are regarded as word separators and are replaced to hyphens.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
train := stringcase.TrainCaseWithKeep("foo-bar100%baz", "%")
fmt.Printf("train = %s\n", train)
}
Output: train = Foo-Bar100%-Baz
func TrainCaseWithSep ¶
Converts a string to train case using the specified characters as separators.
This function takes a string as its argument, then returns a string of which the case style is train case.
This function targets only the upper and lower cases of ASCII alphabets for capitalization, and the characters specified as the second argument of this function are regarded as word separators and are replaced to hyphens.
Example ¶
package main
import (
"fmt"
"github.com/sttk/stringcase"
)
func main() {
train := stringcase.TrainCaseWithSep("foo-bar100%baz", "- ")
fmt.Printf("train = %s\n", train)
}
Output: train = Foo-Bar100%-Baz
Types ¶
This section is empty.