strings: Index | Examples | Files

package stringsp

import ""

Package stringsp is a plus to the standard "strings" package.



Package Files

set.go slice.go strings.go

func CallbackFields Uses

func CallbackFields(s string, prepare func(n int), newField func(f string))

CallbackFields calls CallbackFieldsFunc with unicode.IsSpace.


CallbackFields("Hello World ", func(n int) {
    fmtp.Printfln("Totally %d lines:", n)
}, func(f string) {
    fmtp.Printfln("  %s", f)


Totally 2 lines:

func CallbackFieldsFunc Uses

func CallbackFieldsFunc(s string, isSpace func(rune) bool, prepare func(n int), newField func(f string))

CallbackFieldsFunc is similar to strings.FieldsFunc but results are returned by two callback functions. prepare is firstly called with the number of total fields. Then each field is given by calling newField in order. If no fields are found, prepare is called with a zero value.

This function is especially useful when we want to split a string into a slice of named types other than strings or into a non-slice data structure at all.

func Compare Uses

func Compare(a, b string) int

Compares returns -1 if a < b, 1 if a > b, 0 otherwise.

func FullJoin Uses

func FullJoin(a []string, prefix, sep, suffix string) string

FullJoin is similar to strings.Join with additional prefix/suffix if a is non-empty.


a := []string{
    "item1", "item two",
fmt.Println(FullJoin(a, "(", "), (", ")"))


(item1), (item two)

func Get Uses

func Get(s *string) string

Get safely returns the pointed contents of a string pionter. Returns "" for a nil pointer.

func IndentLinesExceptFirst Uses

func IndentLinesExceptFirst(s, indent string) string

IndentLinesExceptFirst appends a leading indent to each lines of the string except the first line.

func LessFunc Uses

func LessFunc(l []string) func(i, j int) bool

LessFunc returns a closure for comparing elements of a string slice.

func MatchPrefix Uses

func MatchPrefix(s, prefix string) (string, bool)

MatchPrefix checks whether the specified string has a prefix, if so a string removing the prefix is returned; otherwise the original string is returned

func SliceInsert Uses

func SliceInsert(s []string, index int, e ...string) []string

SliceInsert inserts some elements at index-th position and resturns the result slice.

func SliceRemove Uses

func SliceRemove(s []string, index int) []string

SliceRemove removes the index-th element from the slice and returns the result slice.

type Set Uses

type Set map[string]struct{}

Set is a set of strings

func NewSet Uses

func NewSet(els ...string) (s Set)

NeSet creates a string set with specified elements. You need to use this function only when you want to create a Set with intial elements. Different from a normal map, a nil value of Set is ok to add elemnents by calling the Add method.

func (*Set) Add Uses

func (s *Set) Add(els ...string) Set

Add adds elements to the set. The set can be nil

func (Set) Contain Uses

func (s Set) Contain(el string) bool

Contain returns true if the specified element is in the set, false otherwise

func (Set) Delete Uses

func (s Set) Delete(els ...string) Set

Delete removes elements from the set

func (Set) Elements Uses

func (s Set) Elements() (els []string)

Elements returns all elements in the set as a string slice. NOTE the order of elements may change even if the set does not change.

func (Set) Equal Uses

func (s Set) Equal(t Set) bool

Equal checks whether the set has same elements with another set.

func (Set) String Uses

func (s Set) String() string

String returns the string presentation of the set

Package stringsp imports 4 packages (graph) and is imported by 17 packages. Updated 2016-07-21. Refresh now. Tools for package owners.