xstrings

package
v0.0.0-...-89edfd8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CharsNum contains numbers from 0-9
	CharsNum = "0123456789"
	// CharsAlpha contains the full English alphabet: letters a-z and A-Z
	CharsAlpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	// CharsAlphaNum is a combination of CharsNum and CharsAlpha
	CharsAlphaNum = CharsNum + CharsAlpha
	// CharsASCII contains all printable ASCII characters in code range [32, 126]
	CharsASCII = CharsAlphaNum + " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
)

Variables

View Source
var (
	// ErrInvalidLengthSpecified is returned when the length specified is invalid
	ErrInvalidLengthSpecified = errors.New("invalid password length specified")
	// ErrInvalidDictSpecified is returned when the dictionary specified is invalid
	ErrInvalidDictSpecified = errors.New("invalid password dictionary specified")
)

Functions

func Announcement

func Announcement(message string) string

func Center

func Center(str, padding string, width uint) string

func CompactJSON

func CompactJSON(in string) string

func Format

func Format(formatStr string, a ...interface{}) string

Given a string with brackets like "{} foo {}" and a number of inputs equivalent to the number of brackets in the string, like "too", "baz", this function will return a string such that an item is matched with its corresponding bracket. So the function stringit.Format("{} foo {}", "too", "baz") wil yield "too foo baz"

func FrequencyDistributionScore

func FrequencyDistributionScore(bs []byte) float64

FrequencyDistributionScore computes a heuristic score for the frequency distribution of letters in bs, relative to masterFreq. It also applies some heurstics to determine if the text looks like English at all. The lower the score, the closer to English it looks.

func GenerateSecureString

func GenerateSecureString(l int, dict string) (string, error)

Generate generates a cryptographically secure and unbiased string of length 'l' using alphabet 'dict'

func IsInSlice

func IsInSlice(str string, list []string) bool

func KLDivergence

func KLDivergence(p, q []float64) float64

func Len

func Len(str string) int

func MaskString

func MaskString(orig, mask string, revealLength, length int) string

func PosInSlice

func PosInSlice(str string, list []string) int

func PrettyJson

func PrettyJson(data interface{}) (string, error)

func RandStringWithLengthLimit

func RandStringWithLengthLimit(n int) string

func Reverse

func Reverse(s string) (result string)

func Sha1

func Sha1(in string) string

func Sha256

func Sha256(in string) string

func Sha512

func Sha512(in string) string

func StringBetween

func StringBetween(str, start, end string) string

func StringsBetween

func StringsBetween(str, start, end string) (between []string)

func SubString

func SubString(str string, startIndex, endIndex int) string

func SubStringEnd

func SubStringEnd(str string, endIndex int) string

func SubStringStart

func SubStringStart(str string, startIndex int) string

func ToCamel

func ToCamel(s string) string

func ToCamelLower

func ToCamelLower(s string) string

func ToOrdinise

func ToOrdinise(number int) string

func ToSnake

func ToSnake(s string) string

func ToSnakeUpper

func ToSnakeUpper(s string) string

func ToSpinal

func ToSpinal(s string) string

func ToTrain

func ToTrain(s string) string

func Truncate

func Truncate(str string, length int, withExtenders bool) string

func UUID4

func UUID4() (string, bool)

Types

type Formatter

type Formatter struct {
	FloatFmt  byte
	FloatPrec int
	IntBase   int
	UintBase  int
}

func (*Formatter) FormatStr

func (f *Formatter) FormatStr(formatStr string, a ...interface{}) string

type Gen

type Gen isaac64.Rand

Gen is a version 4 UUID generator backed by a CSPRNG.

func UUIDNewGen

func UUIDNewGen() *Gen

NewGen initializes and returns a new version 4 UUID generator.

func (*Gen) UUIDNewV4

func (g *Gen) UUIDNewV4() UUID

NewV4 returns a fresh version 4 UUID.

type UUID

type UUID [16]byte

UUID represents a UUID (any version). This is explicitly an array so that users can directly slice the binary representation.

func UUIDParse

func UUIDParse(s string) (UUID, error)

Parse a UUID (any version) from its string representation.

func (UUID) UUIDMarshalBinary

func (u UUID) UUIDMarshalBinary() ([]byte, error)

func (UUID) UUIDString

func (u UUID) UUIDString() string

func (*UUID) UUIDUnmarshalBinary

func (u *UUID) UUIDUnmarshalBinary(data []byte) error

Jump to

Keyboard shortcuts

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