xstrings

package
v0.0.0-...-519d24f Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package xstrings provides extended utility functions for strings

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fold

func Fold(s string) string

Fold transforms all runes to their canonical width. unicode string

func Narrow

func Narrow(s string) string

Narrow transforms all runes to the narrow unicode string

func Or

func Or(arr ...string) string

Or returns the first element of string array which is not empty

Example
fmt.Println(Or("a", "b"))
fmt.Println(Or("", "b"))
Output:

a
b

func SplitAndTrim

func SplitAndTrim(s string, sep string) []string

SplitAndTrim is like strings.Split but spaces in each of item are trimmed

Example
fmt.Println(SplitAndTrim("a, b, c ,d,,f,", ","))
Output:

[a b c d f]

func SplitAndTrimAsMap

func SplitAndTrimAsMap(s string, sep string) map[string]struct{}

SplitAndTrimAsMap is like SplitAndTrim but returns an map[string]bool where the map key is the string flagment included in

Example
m := SplitAndTrimAsMap("a, b, c ,d,,f,", ",")
_, ok := m["a"]
_, not := m["z"]
fmt.Println(ok, not)
Output:

true false

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts the string to the one by snake case.

Example
fmt.Println(
	ToSnakeCase("A"),
	ToSnakeCase("FooBar"),
	ToSnakeCase("APIDoc"),
	ToSnakeCase("OK"),
	ToSnakeCase("IsOK"),
	ToSnakeCase("camelCase"),
)
Output:

a foo_bar api_doc ok is_ok camel_case

func Widen

func Widen(s string) string

Widen transforms all runes to the widen unicode string

Types

This section is empty.

Jump to

Keyboard shortcuts

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