strutil

package
v0.3.37 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidStartPosition = errors.New("start position is invalid")
	ErrInvalidStopPosition  = errors.New("stop position is invalid")
)

Functions

func Addr2Hex

func Addr2Hex(str string) (string, error)

Addr2Hex converts address string to hex string, only support ipv4.

func AnyBlank

func AnyBlank(ss []string) bool

AnyBlank return true if ss has empty element

func Append

func Append(ss ...string) string

func Contain

func Contain(ss []string, str string) bool

Contain determines whether the str is in the ss.

func Contains

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

func Copy added in v0.3.12

func Copy(s string) string

Copy copies a string to make it immutable

func Diff

func Diff(base, exclude []string) (result []string)

Diff Creates an slice of slice values not included in the other given slice.

func Filter

func Filter(ss []string, str string) (dt []string)

func Find

func Find(ss []string, str string) int

func HasEmpty

func HasEmpty(args ...string) bool

func Hex2Addr

func Hex2Addr(str string) (string, error)

Hex2Addr converts hex string to address.

func NotEmpty

func NotEmpty(args ...string) bool

func Rand added in v0.3.11

func Rand() string

func RandId added in v0.3.11

func RandId() string

func Randn added in v0.3.11

func Randn(n int) string

func Remove

func Remove(ss []string, s string) (result []string)

Remove remove item from slice

func Reverse

func Reverse(s string) string

Reverse returns its argument string reversed rune-wise left to right.

func Seed added in v0.3.11

func Seed(seed int64)

func SubStr

func SubStr(s string, start, length int) string

SubStr 截取字符串

func Substr

func Substr(str string, start int, stop int) (string, error)

Substr returns runes between start and stop [start, stop) regardless of the chars are ascii or utf8

func TakeOne

func TakeOne(valid, or string) string

func TakeWithPriority

func TakeWithPriority(fns ...func() string) string

func Ternary added in v0.3.22

func Ternary(s1, s2 string) string

func ToBytes

func ToBytes(str string) []byte

#nosec G103 ToBytes returns a byte pointer without allocation

func ToFloat64

func ToFloat64(s string) (float64, error)

func ToInt

func ToInt(s string) (int, error)

func ToInt64

func ToInt64(str string) (int64, error)

func Union

func Union(first, second []string) []string

func Unique

func Unique(ss []string) (result []string)

Unique

Types

type Builder

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

A Builder is used to efficiently build a string using Write methods. It minimizes memory copying. The zero value is ready to use. Do not copy a non-zero Builder.

func GetBuilder

func GetBuilder() *Builder

func (*Builder) Append

func (b *Builder) Append(ss ...string)

func (*Builder) Cap

func (b *Builder) Cap() int

Cap returns the capacity of the builder's underlying byte slice. It is the total space allocated for the string being built and includes any bytes already written.

func (*Builder) Grow

func (b *Builder) Grow(n int)

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

func (*Builder) Len

func (b *Builder) Len() int

Len returns the number of accumulated bytes; b.Len() == len(b.String()).

func (*Builder) Reset

func (b *Builder) Reset()

Reset resets the Builder to be empty.

func (*Builder) String

func (b *Builder) String() string

String returns the accumulated string.

func (*Builder) Write

func (b *Builder) Write(p []byte) (int, error)

Write appends the contents of p to b's buffer. Write always returns len(p), nil.

func (*Builder) WriteByte

func (b *Builder) WriteByte(c byte) error

WriteByte appends the byte c to b's buffer. The returned error is always nil.

func (*Builder) WriteRune

func (b *Builder) WriteRune(r rune) (int, error)

WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. It returns the length of r and a nil error.

func (*Builder) WriteString

func (b *Builder) WriteString(s string) (int, error)

WriteString appends the contents of s to b's buffer. It returns the length of s and a nil error.

type Strings

type Strings []string

Strings ...

func KickEmpty

func KickEmpty(ss []string) Strings

KickEmpty kick empty elements from ss

func Split

func Split(raw string, sep string) Strings

Split ...

func (Strings) Head

func (ss Strings) Head() string

Head ...

func (Strings) Head2

func (ss Strings) Head2() (h0, h1 string)

Head2 ...

func (Strings) Head3

func (ss Strings) Head3() (h0, h1, h2 string)

Head3 ...

func (Strings) Head4

func (ss Strings) Head4() (h0, h1, h2, h3 string)

Head4 ...

func (Strings) HeadT

func (ss Strings) HeadT() (string, Strings)

HeadT ...

Jump to

Keyboard shortcuts

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