stringutils

package
v0.0.0-...-536613a Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

README

This package provides helper functions for dealing with strings

Documentation

Overview

Package stringutils provides helper functions for dealing with strings.

Package stringutils provides helper functions for dealing with strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(str string) string

Base64Decode base64 decode string

func Base64Encode

func Base64Encode(str string) string

Base64Encode base64 encode string

func Base64ForURLDecode

func Base64ForURLDecode(str string) string

Base64ForURLDecode decode string to url base64

func Base64ForURLEncode

func Base64ForURLEncode(unencodedText string) string

Base64ForURLEncode encode string from url base64

func Contains

func Contains(strlist []string, str string) bool

Contains return true if slice contains str

func ContainsIgnoreCase

func ContainsIgnoreCase(strlist []string, str string) bool

ContainsIgnoreCase return true if slice contains str, ignore case

func FindFirstParenStrings

func FindFirstParenStrings(r *regexp.Regexp, s string) []string

FindFirstParenStrings returns slice of first paren

func GenerateRandomASCIIString

func GenerateRandomASCIIString(n int) string

GenerateRandomASCIIString generates an ASCII random stirng with length n.

func GenerateRandomAlphaOnlyString

func GenerateRandomAlphaOnlyString(n int) string

GenerateRandomAlphaOnlyString generates an alphabetical random string with length n.

func HasPrefixIgnoreCase

func HasPrefixIgnoreCase(strlist []string, str string) bool

HasPrefixIgnoreCase tests whether the string str begins with prefix, ignore case.

func InSlice

func InSlice(slice []string, s string) bool

InSlice tests whether a string is contained in a slice of strings or not. Comparison is case insensitive

func IsAppname

func IsAppname(str string) bool

IsAppname returns true if name valid

func IsEmail

func IsEmail(str string) bool

IsEmail return true if str is email

func IsUUID

func IsUUID(str string) bool

IsUUID return true if str is uuid

func IsUsername

func IsUsername(str string) bool

IsUsername return true if str is username

func Marshal

func Marshal(obj interface{}) (string, error)

Marshal obj to string

func ReaderToBytes

func ReaderToBytes(stream io.Reader) []byte

ReaderToBytes reader to bytes

func ReaderToString

func ReaderToString(stream io.Reader) string

ReaderToString reader to string

func ShellQuoteArguments

func ShellQuoteArguments(args []string) string

ShellQuoteArguments takes a list of strings and escapes them so they will be handled right when passed as arguments to an program via a shell

func ToBoolean

func ToBoolean(str string) (bool, error)

ToBoolean convert the input string to a boolean.

func ToFloat

func ToFloat(str string) (float64, error)

ToFloat convert the input string to a float, or 0.0 if the input is not a float.

func ToInt

func ToInt(str string) (int64, error)

ToInt convert the input string to an integer, or 0 if the input is not an integer.

func ToString

func ToString(obj interface{}) string

ToString convert the input to a string.

func Truncate

func Truncate(s string, maxlen int) string

Truncate truncates a string to maxlen.

func UUID

func UUID() string

UUID return new uuid

func Unmarshal

func Unmarshal(str string, obj interface{}) error

Unmarshal string to obj

Types

type StrSlice

type StrSlice struct {
	// contains filtered or unexported fields
}

StrSlice representes a string or an array of strings. We need to override the json decoder to accept both options.

func NewStrSlice

func NewStrSlice(parts ...string) *StrSlice

NewStrSlice creates an StrSlice based on the specified parts (as strings).

func (*StrSlice) Len

func (e *StrSlice) Len() int

Len returns the number of parts of the StrSlice.

func (*StrSlice) MarshalJSON

func (e *StrSlice) MarshalJSON() ([]byte, error)

MarshalJSON Marshals (or serializes) the StrSlice into the json format. This method is needed to implement json.Marshaller.

func (*StrSlice) Slice

func (e *StrSlice) Slice() []string

Slice gets the parts of the StrSlice as a Slice of string.

func (*StrSlice) ToString

func (e *StrSlice) ToString() string

ToString gets space separated string of all the parts.

func (*StrSlice) UnmarshalJSON

func (e *StrSlice) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes the byte slice whether it's a string or an array of strings. This method is needed to implement json.Unmarshaler.

Jump to

Keyboard shortcuts

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