strings

package
v0.0.0-...-c8a214a Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: Apache-2.0 Imports: 4 Imported by: 11

Documentation

Overview

Package strings introduces additional utilities for dealing with strings and slices of strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PadLeft

func PadLeft(s string, i int) string

PadLeft prepends string s with i spaces.

func PadLeftWith

func PadLeftWith(s string, i int, p string) string

PadLeftWith prepends string s with i instances of padding p.

func Split2

func Split2(s, delim string) (string, string)

Split2 splits a string on the first occurrence of the given delimiter and returns the portions of the original string before and after the delimiter. If no delimiter appears in the given string, the entire string is returned as the first result and the second result is empty. If multiple delimiters appear in the string, the strings are split at the first occurrence. The delimiter may appear at the start of end of the string, resulting in either the first or second result being the empty string.

func SplitFirstColon

func SplitFirstColon(s string) (string, string)

SplitFirstColon invokes Split2 to split a string of the form "A:B".

func SplitFirstEqual

func SplitFirstEqual(s string) (string, string)

SplitFirstEqual invokes Split2 to split a string of the form "A=B".

func SplitHostPort

func SplitHostPort(s string) (string, int, error)

SplitHostPort splits a string of the form "host:port". After splitting the string via net.SplitHostPort, the port is converted to an integer. If there is an error splitting the host and port, if port cannot be converted into an integer, or if port is not in the range [0, 65535], an error is returned.

Types

type Set

type Set map[string]bool

Set represets set-like operations for strings.

func NewSet

func NewSet(ss ...string) Set

NewSet ccreates a new Set containing the provided strings as an initial values stored in the set.

func (Set) Contains

func (ss Set) Contains(k string) bool

Contains returns true if the set contains some key k.

func (Set) Equals

func (ss Set) Equals(o Set) bool

Equals returns true if two Sets contain the same items.

func (Set) Put

func (ss Set) Put(k string)

Put adds a new key to the set.

func (Set) Remove

func (ss Set) Remove(k string)

Remove removes an item from the set, no change is made if it is not present.

func (Set) Slice

func (ss Set) Slice() []string

Slice returns the Set as a slice of values.

func (Set) Transform

func (ss Set) Transform(fn func(string) string)

Transform will apply some transformation to each item in the set.

Jump to

Keyboard shortcuts

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