strutil

package module
v0.0.0-...-96e0b22 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2016 License: MIT Imports: 7 Imported by: 0

README

strutil Build Status Coverage Status GoDoc

This Go package provides useful string utilities.

Install

go get github.com/stephanos/strutil

Documentation

godoc.org

Credits

License

MIT (see LICENSE).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And(s ...string) string

And creates a conjunction with "and" from the passed-in words.

func DeleteWhitespace

func DeleteWhitespace(s string) string

DeleteWhitespace returns a version of the passed-in string with all whitespaces (as by unicode.IsSpace) removed.

func FromInt

func FromInt(i int) string

FromInt returns the string representation of i (with base 10).

func Head(s string) string

Head returns a substring containing the first char.

func IndexAfter

func IndexAfter(s, sep string) int

IndexAfter returns the index directly after the first instance of sep in s, or -1 if sep is not present in s.

func Init

func Init(s string) string

Init returns a substring with all chars except the last.

func IsBlank

func IsBlank(s string) bool

IsBlank returns whether a string is whitespace or empty.

func IsEmpty

func IsEmpty(s string) bool

IsEmpty returns whether a string is empty ("").

func Last

func Last(s string) string

Last returns a substring containing the last char.

func Lines

func Lines(s string) []string

Lines returns sequence of lines of passed-in str.

func LowerFirst

func LowerFirst(s string) string

LowerFirst returns str with the first char lower-cased.

func Or

func Or(s ...string) string

Or creates a conjunction with "or" from the passed-in words.

func Reverse

func Reverse(s string) (rev string)

Reverse returns a reversed version of s.

func ShrinkWhitespace

func ShrinkWhitespace(s string) string

ShrinkWhitespace returns a version of the passed-in string with whitespace removed from the end and beginning as well as all whitespace in-between shrunken to a single space.

func Surround

func Surround(s, around string) string

Surround appends and prepends a string to another.

func Tail

func Tail(s string) string

Tail returns a substring with all chars except the first.

func Take

func Take(s string, n int) string

Take returns a substring of the first n elements. If n is greater than the length of th string, the whole string is returned.

func TakeAfter

func TakeAfter(s, pattern string) string

TakeAfter searches a string from right to left for a pattern and returns a substring consisting of the characters in the string that are to the left of the pattern or all string if no match found.

func TakeBefore

func TakeBefore(s, pattern string) string

TakeBefore searches a string from left to right for a pattern and returns a substring consisting of the characters in the string that are to the left of the pattern or all string if no match found.

func TakeRight

func TakeRight(s string, n int) string

TakeRight returns a substring of the last n elements. If n is greater than the length of the string, the whole string is returned.

func TakeRightAfter

func TakeRightAfter(s, pattern string) string

TakeRightAfter searches a string from right to left for a pattern and returns a substring consisting of the characters in the string that are to the right of the pattern or all string if no match found.

func TakeRightBefore

func TakeRightBefore(s, pattern string) string

TakeRightBefore searches a string from left to right for a pattern and returns a substring consisting of the characters in the string that are to the right of the pattern or all string if no match found.

func ToInt

func ToInt(s string) (int, error)

ToInt returns the corresponding int (base 10) for a passed-in string.

func Truncate

func Truncate(s string, n int, suffix ...string) string

Truncate returns a substring of the first n elements and appends a suffix ("..." by default) to the result.

If the suffix is longer than the truncated part, the original string is returned.

func UpperFirst

func UpperFirst(s string) string

UpperFirst returns str with the first char upper-cased.

func WordWrap

func WordWrap(s string, width int) string

WordWrap wraps paragraphs of text to width.

Types

This section is empty.

Jump to

Keyboard shortcuts

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