string

package
v0.0.0-...-f9328b3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

This package are test package of golang.

It's include golang implements of karmia-utility-string.

https://github.com/fujimakishouten/karmia-utility-string

Index

Examples

Constants

View Source
const NORMALIZE_FORM_NFC string = `NFC`
View Source
const NORMALIZE_FORM_NFD string = `NFD`
View Source
const NORMALIZE_FORM_NFKC string = `NFKC`
View Source
const NORMALIZE_FORM_NFKD string = `NFKD`

Variables

This section is empty.

Functions

func IsString

func IsString(value interface{}) bool

IsString are return true if type of the value are string.

Example
type Test struct {
	key   string
	value interface{}
}

fmt.Println(`Kosaka Honoka`)
fmt.Println(1)
fmt.Println([]byte(`Kosaka Honoka`))
fmt.Println(Test{key: "name", value: "Kosaka Honoka"})
Output:

true
false
false
false

func KebabCase

func KebabCase(value string) string

KebabCase are are make value kabeb case.

Example
fmt.Println(KebabCase(`KosakaHonoka`))
fmt.Println(KebabCase(`kosakaHonoka`))
fmt.Println(KebabCase(`kosaka_honoka`))
fmt.Println(KebabCase(`kosaka-honoka`))
Output:

kosaka-honoka
kosaka-honoka
kosaka-honoka
kosaka-honoka

func LowerCamelCase

func LowerCamelCase(value string) string

LowerCamelCase are make value lower camel case.

Example
fmt.Println(LowerCamelCase(`KosakaHonoka`))
fmt.Println(LowerCamelCase(`kosakaHonoka`))
fmt.Println(LowerCamelCase(`kosaka_honoka`))
fmt.Println(LowerCamelCase(`kosaka-honoka`))
Output:

kosakaHonoka
kosakaHonoka
kosakaHonoka
kosakaHonoka

func Normalize

func Normalize(value string, normalizationForm ...string) string

Normalize are normalize string.

Example
// Normalize string with default normalization form (NFKC).
fmt.Println(Normalize("\u202b123\r\nABC\rdef\nアイウエオガ"))

// Normalize string with specific normalization form (NFKD).
fmt.Println(Normalize("123\nABC\ndef\nアイウエオガ", NORMALIZE_FORM_NFKD))
Output:

// Normalize string with default normalization form (NFKC).
123
ABC
def
アイウエオガ

// Normalize string with specific normalization form (NFKD)
123
ABC
def
アイウエオガ

func Parse

func Parse(value string, options ...string) map[string]string

Parse are parse "key1=value1,key2=value2" like string to map of string.

Example
fmt.Println(Parse(`key1=value1,key2=value2,key3=value3`))
fmt.Println(Parse(`key1=value1, key2=value2, key3=value3`))
fmt.Println(Parse(`key1=value1&key2=value2&key3=value3`, `&`))
fmt.Println(Parse(`keys:value1;key2:value2;key3:value3`, `;`, `:`))
Output:

map[key1:value1 key2:value2 key3:value3]
map[key1:value1 key2:value2 key3:value3]
map[key1:value1 key2:value2 key3:value3]
map[key2:value2 key3:value3 keys:value1]

func SnakeCase

func SnakeCase(value string) string

SnakeCase are make value snake case.

Example
fmt.Println(SnakeCase(`KosakaHonoka`))
fmt.Println(SnakeCase(`kosakaHonoka`))
fmt.Println(SnakeCase(`kosaka_honoka`))
fmt.Println(SnakeCase(`kosaka-honoka`))
Output:

kosaka_honoka
kosaka_honoka
kosaka_honoka
kosaka_honoka

func Strip

func Strip(value string, delimiter ...string) string

Strip are alias of the Trim.

Example
fmt.Println(Strip("\r    \x00Kosaka Honoka\x0B\n\t"))
Output:

Kosaka Honoka

func StripLeft

func StripLeft(value string, delimiter ...string) string

StripLeft are alias of the TrimLeft.

Example
fmt.Println(StripLeft("\r    \x00Kosaka Honoka\x0B\n\t"))
Output:

Kosaka Honoka\x0B\n\t    // "\x0B\n\t" are invisible

func StripRight

func StripRight(value string, delimiter ...string) string

StripRight are alias of the TrimRight.

Example
fmt.Println(StripRight("\r    \x00Kosaka Honoka\x0B\n\t"))
Output:

\r    \x00Kosaka Honoka    // "/r    \x00" are invisible

func ToBoolean

func ToBoolean(value string) bool

Convert from `true`, `on`, `1` strings to true and others to false

Example
fmt.Println(ToBoolean(`true`))
fmt.Println(ToBoolean(`false`))
fmt.Println(ToBoolean(`1`))
fmt.Println(ToBoolean(`0`))
fmt.Println(ToBoolean(`on`))
fmt.Println(ToBoolean(`off`))
Output:

true
false
true
false
true
false

func Trim

func Trim(value string, delimiter ...string) string

Trim are strip whitespace from the beginning and end of a string.

Example
fmt.Println(Trim("\r    \x00Kosaka Honoka\x0B\n\t"))
Output:

Kosaka Honoka

func TrimLeft

func TrimLeft(value string, delimiter ...string) string

Trim are strip whitespace from the beginning of a string.

Example
fmt.Println(TrimLeft("\r    \x00Kosaka Honoka\x0B\n\t"))
Output:

Kosaka Honoka\x0B\n\t    // "\x0B\n\t" are invisible

func TrimRight

func TrimRight(value string, delimiter ...string) string

Trim are strip whitespace from the end of a string.

Example
fmt.Println(TrimRight("\r    \x00Kosaka Honoka\x0B\n\t"))
Output:

\r    \x00Kosaka Honoka    // "/r    \x00" are invisible

func Unquote

func Unquote(value string) string

Unquote are strip quote character from the beginning and end of a string.

Example
fmt.Println(Unquote(`"Kosaka Honoka"`))
fmt.Println(Unquote(`'Kosaka Honoka'`))
fmt.Println(Unquote("`Kosaka Honoka`"))
fmt.Println(Unquote(`"` + "Kosaka Honoka`"))
Output:

Kosaka Honoka
Kosaka Honoka
Kosaka Honoka
"Kosaka Honoka`

func UpperCamelCase

func UpperCamelCase(value string) string

UpperCamelCase are make a value upper camel case.

Example
fmt.Println(UpperCamelCase(`KosakaHonoka`))
fmt.Println(UpperCamelCase(`kosakaHonoka`))
fmt.Println(UpperCamelCase(`kosaka_honoka`))
fmt.Println(UpperCamelCase(`kosaka-honoka`))
Output:

KosakaHonoka
KosakaHonoka
KosakaHonoka
KosakaHonoka

func Zfill

func Zfill(value string, width int) string

Zfill are return a copy of the string left filled with `0`

Example
fmt.Println(Zfill(`1`, 5))
fmt.Println(Zfill(`+1`, 5))
fmt.Println(Zfill(`-1`, 5))
Output:

00001
+00001
-00001

Types

This section is empty.

Jump to

Keyboard shortcuts

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