This commit is contained in:
cdle
2023-06-07 17:33:29 +08:00
parent 90f302a682
commit c74c9b130e
7 changed files with 124 additions and 6 deletions
+27
View File
@@ -3,10 +3,13 @@ package core
import (
"bytes"
"fmt"
"math/rand"
"net/url"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
"github.com/cdle/sillyplus/emoji"
"github.com/cdle/sillyplus/utils"
@@ -15,9 +18,33 @@ import (
type Strings struct {
}
func (sender *Strings) Random(length int, substr string) string {
ws := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
if substr != "" {
ws = substr
}
rand.Seed(time.Now().UnixNano())
letters := []rune(ws)
b := make([]rune, length)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
func (sender *Strings) JoinFilepath(elem ...string) string {
return filepath.Join(elem...)
}
func (sender *Strings) Contains(s, substr string) bool {
return strings.Contains(s, substr)
}
func (sender *Strings) HasPrefix(s, substr string) bool {
return strings.HasPrefix(s, substr)
}
func (sender *Strings) HasSuffix(s, substr string) bool {
return strings.HasSuffix(s, substr)
}
func (sender *Strings) Replace(s string, old string, new string, n int) string {
if n == 0 {