strutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package strutil provides functional utils for string.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IString

type IString interface {
	Min(x, y string) string
	Max(x, y string) string
	Filter(ints []string, predict func(string) bool) []string
	Find(ints []string, predict func(string) bool) (string, bool)
	FindIndex(ints []string, predict func(string) bool, fromIndex ...int) int
	FindLastIndex(ints []string, predict func(string) bool, fromIndex ...int) int
	ForEach(ints []string, provided func(string))
	Includes(ints []string, e string) bool
	IndexOf(ints []string, e string, fromIndex ...int) int
	LastIndexOf(ints []string, e string, fromIndex ...int) int
	From(ints []string, mapFn ...func(string) string) []string
	Of(ints ...string) []string
	Concat(ints ...[]string) []string
	Every(ints []string, predict func(string) bool) bool
	Some(ints []string, predict func(string) bool) bool
	Fill(ints []string, value string, startEndIndex ...int)
	Join(ints []string, sep ...string) string
	Map(ints []string, m func(string) string) []string
	Pop(ints []string) (string, bool, []string)
	Push(ints []string, es ...string) (int, []string)
	Reduce(ints []string, accum func(string, string) string, init ...string) string
	ReduceRight(ints []string, accum func(string, string) string, init ...string) string
	Reverse(ints []string) []string
	Shift(ints []string) (string, bool, []string)
	Unshift(ints []string, es ...string) (int, []string)
	Slice(ints []string, startEndIndex ...int) []string
	Sort(ints []string, less ...func(int, int) bool)
	Shuffle(ints []string)
	String(ints []string) string
	Drop(ints []string, n ...int) []string
	Head(ints []string) (string, bool)
	Initial(ints []string) []string
	Last(ints []string) (string, bool)
	Nth(ints []string, n ...int) (string, bool)
	Pull(ints []string, vs ...string) []string
	Difference(ints []string, vs ...[]string) []string
	Intersection(vs ...[]string) []string
	Without(ints []string, vs ...string) []string
	Remove(ints []string, predict func(string) bool) []string
	Tail(ints []string) []string
	Take(ints []string, n ...int) []string
	Union(ints ...[]string) []string
	Uniq(ints []string) []string
	Equal(s1, s2 []string) bool
}

IString is the String interface.

type String

type String struct{}

String for string type slice.

func NewString

func NewString() *String

NewString creates a new String instance.

func (*String) CamelCase

func (*String) CamelCase(input string, pascalCase ...bool) string

CamelCase convert dash/dot/underscore/space separated string to camelCase pascalCase define whether to uppercase the first character

func (*String) Concat

func (*String) Concat(ints ...[]string) []string

Concat merges two or more slices.

func (*String) Difference

func (i *String) Difference(ints []string, vs ...[]string) []string

Difference creates a slice of values not included in the other given slices.

func (*String) Drop

func (*String) Drop(ints []string, n ...int) []string

Drop creates a slice with n elements dropped from the beginning.

func (*String) Equal

func (*String) Equal(s1, s2 []string) bool

Equal performs a deep comparison between two slice values.

func (*String) Every

func (*String) Every(ints []string, predict func(string) bool) bool

Every tests whether all elements in the slice pass the predict implemented.

func (*String) Fill

func (*String) Fill(ints []string, value string, startEndIndex ...int)

Fill fills all the elements of a slice from a start index to an end index with a static value. the end index is not included.

func (*String) Filter

func (*String) Filter(ints []string, predict func(string) bool) []string

Filter creates a new slice with all elements that pass the predict implemented.

func (*String) Find

func (*String) Find(ints []string, predict func(string) bool) (string, bool)

Find returns the value of the first element in the slice that satisfies the provided predict function. otherwise false is returned.

func (*String) FindIndex

func (*String) FindIndex(ints []string, predict func(string) bool, fromIndex ...int) int

FindIndex returns the index of the first element in the slice that satisfies the provided predict function. otherwise -1 is returned.

func (*String) FindLastIndex

func (*String) FindLastIndex(ints []string, predict func(string) bool, fromIndex ...int) int

FindLastIndex is like FindIndex except that it iterates over elements from right to left.

func (*String) ForEach

func (*String) ForEach(ints []string, provided func(string))

ForEach executes a provided function once for each slice element.

func (*String) From

func (*String) From(ints []string, mapFn ...func(string) string) []string

From creates a new, shallow-copied slice.

func (*String) Head

func (*String) Head(ints []string) (string, bool)

Head gets the first element of slice.

func (*String) Includes

func (*String) Includes(ints []string, e string) bool

Includes determines whether a slice includes a certain element, returning true or false.

func (*String) IndexOf

func (*String) IndexOf(ints []string, e string, fromIndex ...int) int

IndexOf returns the first index at which a given element can be found in the slice, or -1 if it is not present.

func (*String) Initial

func (*String) Initial(ints []string) []string

Initial gets all but the last element of slice.

func (*String) Intersection

func (i *String) Intersection(vs ...[]string) []string

Intersection creates a slice of unique values that are included in all given slices.

func (*String) Join

func (*String) Join(ints []string, sep ...string) string

Join joins all elements of a slice into a string.

func (*String) KebabCase

func (*String) KebabCase(input string, separateDigit ...bool) string

KebabCase convert string to kebab-case separateDigit define whether to separate digit from letter

func (*String) Last

func (*String) Last(ints []string) (string, bool)

Last gets the last element of slice.

func (*String) LastIndexOf

func (*String) LastIndexOf(ints []string, e string, fromIndex ...int) int

LastIndexOf returns the last index at which a given element can be found in the slice, or -1 if it is not present.

func (*String) Map

func (*String) Map(ints []string, m func(string) string) []string

Map creates a new slice with the results of calling a provided function on every element in the calling slice.

func (*String) Max

func (*String) Max(x, y string) string

Max returns the larger of x or y.

func (*String) Min

func (*String) Min(x, y string) string

Min returns the smaller of x or y.

func (*String) Nth

func (*String) Nth(ints []string, n ...int) (string, bool)

Nth gets the element at index n of slice. if n is negative, the nth element from the end is returned.

func (*String) Of

func (*String) Of(ints ...string) []string

Of creates a new slice instance with a variable number of arguments.

func (*String) Pop

func (*String) Pop(ints []string) (string, bool, []string)

Pop removes the last element from a slice and returns that element.

func (*String) Pull

func (i *String) Pull(ints []string, vs ...string) []string

Pull removes all given values from slice.

func (*String) Push

func (*String) Push(ints []string, es ...string) (int, []string)

Push adds one or more elements to the end of a slice and returns the new length of the slice.

func (*String) Reduce

func (*String) Reduce(ints []string, accum func(string, string) string, init ...string) string

Reduce applies a function against each element in the slice to reduce it to a single value.

func (*String) ReduceRight

func (*String) ReduceRight(ints []string, accum func(string, string) string, init ...string) string

ReduceRight applies a function against each value of the slice (from right-to-left) to reduce it to a single value.

func (*String) Remove

func (*String) Remove(ints []string, predict func(string) bool) []string

Remove removes all elements from slice that predicate returns truthy for.

func (*String) Reverse

func (*String) Reverse(ints []string) []string

Reverse reverses a slice.

func (*String) Shift

func (*String) Shift(ints []string) (string, bool, []string)

Shift removes the first element from a slice and returns that element.

func (*String) Shuffle

func (*String) Shuffle(ints []string)

Shuffle randomizes the order of elements.

func (*String) Slice

func (*String) Slice(ints []string, startEndIndex ...int) []string

Slice returns a portion of a slice selected from start to end (end not included). start and end indexes are optional, default to zero and length of the slice.

func (*String) SnakeCase

func (*String) SnakeCase(input string, separateDigit ...bool) string

SnakeCase convert string to snake_case separateDigit define whether to separate digit from letter

func (*String) Some

func (*String) Some(ints []string, predict func(string) bool) bool

Some tests whether at least one element in the slice pass the predict implemented.

func (*String) Sort

func (*String) Sort(ints []string, less ...func(int, int) bool)

Sort sorts elements.

func (*String) String

func (i *String) String(ints []string) string

String returns a string representing the specified slice.

func (*String) Tail

func (*String) Tail(ints []string) []string

Tail gets all but the first element of slice.

func (*String) Take

func (*String) Take(ints []string, n ...int) []string

Take creates a slice with n elements taken from the beginning.

func (*String) Titleize

func (*String) Titleize(input string) string

Titleize capitalize every word in string

func (*String) Union

func (i *String) Union(ints ...[]string) []string

Union creates a slice of unique values, in order, from all given slices.

func (*String) Uniq

func (i *String) Uniq(ints []string) []string

Uniq creates a duplicate-free version of a slice.

func (*String) Unshift

func (*String) Unshift(ints []string, es ...string) (int, []string)

Unshift adds one or more elements to the beginning of a slice and returns the new length of the slice.

func (*String) Without

func (i *String) Without(ints []string, vs ...string) []string

Without creates a slice excluding all given values.

Jump to

Keyboard shortcuts

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