utils

package
v0.7.13 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: GPL-3.0 Imports: 19 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ParseUnicode = StringFilterFunc(func(str string) string {
	buf := new(bytes.Buffer)
	chars := []byte(str)
	for i := 0; i < len(str); {
		if chars[i] == 92 && chars[i+1] == 117 {
			t, _ := strconv.ParseInt(string(chars[i+2:i+6]), 16, 32)
			buf.WriteString(fmt.Sprintf("%c", t))
			i += 6
		} else {
			buf.WriteByte(chars[i])
			i++
		}
	}
	return buf.String()
})
View Source
var RemoveSymbolOtherChar = StringFilterFunc(func(str string) string {
	reg := regexp.MustCompile(`\p{So}`)
	for reg.MatchString(str) {
		str = reg.ReplaceAllString(str, "_")
	}
	return str
})
View Source
var ReplaceIllegalChar = StringFilterFunc(func(str string) string {
	reg := regexp.MustCompile(`[\/\\\:\*\?\"\<\>\|]|[\.\s]+$`)
	for reg.MatchString(str) {
		str = reg.ReplaceAllString(str, "_")
	}
	return str
})
View Source
var UnescapeHTMLEntity = StringFilterFunc(html.UnescapeString)

Functions

func GenRandomName

func GenRandomName(n int) string

func GenRandomString added in v0.7.6

func GenRandomString(length int, validChars string) string

func GenUrls

func GenUrls(strs ...string) ([]*url.URL, error)

func GetFFmpegPath added in v0.6.8

func GetFFmpegPath(ctx context.Context) (string, error)

func GetFuncMap added in v0.5.14

func GetFuncMap(config *configs.Config) template.FuncMap

func GetMd5String

func GetMd5String(b []byte) string

func IsFFmpegExist

func IsFFmpegExist(ctx context.Context) bool

func Match1

func Match1(re, str string) string

func ParseString

func ParseString(str string, filter ...StringFilter) string

func PrintStack added in v0.7.8

func PrintStack(ctx context.Context)

Types

type StringFilter

type StringFilter interface {
	Do(string) string
}

type StringFilterChain

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

func NewStringFilterChain

func NewStringFilterChain(filter ...StringFilter) *StringFilterChain

func (*StringFilterChain) Do

func (c *StringFilterChain) Do(str string) string

type StringFilterFunc

type StringFilterFunc func(string) string

func (StringFilterFunc) Do

func (f StringFilterFunc) Do(s string) string

Jump to

Keyboard shortcuts

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