From 295fb16cf70ab65266de8aa7715254b1c216d41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Wed, 7 Sep 2022 22:26:25 +0800 Subject: [PATCH] - add chunk_split --- .gitignore | 4 +- chunk_split.go | 24 ++++ go.mod | 7 +- go.sum | 8 +- vendor/go.dtapp.net/gostring/.gitignore | 4 +- vendor/go.dtapp.net/gostring/README.md | 2 +- vendor/go.dtapp.net/gostring/gostring.go | 152 ----------------------- vendor/go.dtapp.net/gostring/version.go | 3 - vendor/modules.txt | 8 +- version.go | 2 +- 10 files changed, 50 insertions(+), 164 deletions(-) create mode 100644 chunk_split.go delete mode 100644 vendor/go.dtapp.net/gostring/gostring.go delete mode 100644 vendor/go.dtapp.net/gostring/version.go diff --git a/.gitignore b/.gitignore index f04e8b3..114804c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,5 @@ .idea .vscode *.log -goinit.sh -gomod.sh \ No newline at end of file +gomod.sh +/vendor/ diff --git a/chunk_split.go b/chunk_split.go new file mode 100644 index 0000000..cd90580 --- /dev/null +++ b/chunk_split.go @@ -0,0 +1,24 @@ +package gophp + +// ChunkSplit 将字符串拆分成更小的块 +func ChunkSplit(body string, chunklen uint, end string) string { + if end == "" { + end = "\r\n" + } + runes, erunes := []rune(body), []rune(end) + l := uint(len(runes)) + if l <= 1 || l < chunklen { + return body + end + } + ns := make([]rune, 0, len(runes)+len(erunes)) + var i uint + for i = 0; i < l; i += chunklen { + if i+chunklen > l { + ns = append(ns, runes[i:]...) + } else { + ns = append(ns, runes[i:i+chunklen]...) + } + ns = append(ns, erunes...) + } + return string(ns) +} diff --git a/go.mod b/go.mod index 135d894..bf7d6ee 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,9 @@ module go.dtapp.net/gophp go 1.18 -require go.dtapp.net/gostring v1.0.5 +require go.dtapp.net/gostring v1.0.10 + +require ( + go.dtapp.net/gorandom v1.0.1 // indirect + go.dtapp.net/gotime v1.0.5 // indirect +) diff --git a/go.sum b/go.sum index cd92619..740fc62 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,6 @@ -go.dtapp.net/gostring v1.0.5 h1:6sKrSdQ4so80+zvo+VDZ5pgWGREq2niTLv6GIF++HgY= -go.dtapp.net/gostring v1.0.5/go.mod h1:+ggrOvgQDQturi1QGsXEpyRN/ZPoRDaqhMujIk5lrgQ= +go.dtapp.net/gorandom v1.0.1 h1:IWfMClh1ECPvyUjlqD7MwLq4mZdUusD1qAwAdsvEJBs= +go.dtapp.net/gorandom v1.0.1/go.mod h1:ZPdgalKpvFV/ATQqR0k4ns/F/IpITAZpx6WkWirr5Y8= +go.dtapp.net/gostring v1.0.10 h1:eG+1kQehdJUitj9Hfwy79SndMHYOB7ABpWkTs7mDGeQ= +go.dtapp.net/gostring v1.0.10/go.mod h1:L4kREy89a9AraMHB5tUjjl+5rxP1gpXkDouRKKuzT50= +go.dtapp.net/gotime v1.0.5 h1:12aNgB2ULpP6QgQHEUkLilZ4ASvhpFxMFQkBwn0par8= +go.dtapp.net/gotime v1.0.5/go.mod h1:Gq7eNLr2iMLP18UNWONRq4V3Uhf/ADp4bIrS+Tc6ktY= diff --git a/vendor/go.dtapp.net/gostring/.gitignore b/vendor/go.dtapp.net/gostring/.gitignore index 8f33b64..5c75b7d 100644 --- a/vendor/go.dtapp.net/gostring/.gitignore +++ b/vendor/go.dtapp.net/gostring/.gitignore @@ -4,4 +4,6 @@ .idea .vscode *.log -gomod.sh \ No newline at end of file +gomod.sh +*_test.go +/vendor/ diff --git a/vendor/go.dtapp.net/gostring/README.md b/vendor/go.dtapp.net/gostring/README.md index fc529be..4a11776 100644 --- a/vendor/go.dtapp.net/gostring/README.md +++ b/vendor/go.dtapp.net/gostring/README.md @@ -2,7 +2,7 @@ Golang String -📦 Golang 字符串处理 +📦 Golang String [comment]: <> (go) [![godoc](https://pkg.go.dev/badge/go.dtapp.net/gostring?status.svg)](https://pkg.go.dev/go.dtapp.net/gostring) diff --git a/vendor/go.dtapp.net/gostring/gostring.go b/vendor/go.dtapp.net/gostring/gostring.go deleted file mode 100644 index 0929b2f..0000000 --- a/vendor/go.dtapp.net/gostring/gostring.go +++ /dev/null @@ -1,152 +0,0 @@ -package gostring - -import ( - "crypto/hmac" - "crypto/sha256" - "encoding/hex" - "fmt" - "strconv" - "strings" - "unicode/utf8" -) - -// ToString 转换成string -func ToString(value interface{}) string { - if value == nil { - return "" - } - return fmt.Sprint(value) -} - -// ToFloat64 string到float64 -func ToFloat64(s string) float64 { - i, _ := strconv.ParseFloat(s, 64) - return i -} - -// ToInt string到int -func ToInt(s string) int { - i, _ := strconv.Atoi(s) - return i -} - -// ToInt64 string到int64 -func ToInt64(s string) int64 { - i, err := strconv.ParseInt(s, 10, 64) - if err == nil { - return i - } - return int64(ToFloat64(s)) -} - -// ToUint string到uint64 -func ToUint(s string) uint { - i, err := strconv.ParseUint(s, 10, 64) - if err == nil { - return uint(i) - } - return 0 -} - -// ToUint64 string到uint64 -func ToUint64(s string) uint64 { - i, err := strconv.ParseUint(s, 10, 64) - if err == nil { - return i - } - return 0 -} - -// Replace 字符串替换 -func Replace(str, old, new string) string { - return strings.Replace(str, old, new, -1) -} - -func HmacSha256Hex(key, strToSign string) string { - hasHer := hmac.New(sha256.New, []byte(key)) - hasHer.Write([]byte(strToSign)) - return hex.EncodeToString(hasHer.Sum(nil)) -} - -// Space 去除空格 -func Space(str string) string { - return strings.Replace(str, " ", "", -1) -} - -// LineBreak 去除换行符 -func LineBreak(str string) string { - return strings.Replace(str, "\n", "", -1) -} - -// SpaceAndLineBreak 去除空格和去除换行符 -func SpaceAndLineBreak(str string) string { - return LineBreak(Space(str)) -} - -// TrimLastChar 删除字符串中的最后一个 -func TrimLastChar(s string) string { - r, size := utf8.DecodeLastRuneInString(s) - if r == utf8.RuneError && (size == 0 || size == 1) { - size = 0 - } - return s[:len(s)-size] -} - -// Split 字符串分隔 -func Split(s string, sep string) []string { - if len(s) <= 0 { - return []string{} - } - return strings.Split(s, sep) -} - -// Contains 判断字符串是否包含某个字符 -func Contains(s, sep string) bool { - return strings.Contains(s, sep) -} - -func NumericalToString(value interface{}) (string, bool) { - var val string - - switch value.(type) { - default: - return "0", false - case int: - intVal, _ := value.(int) - val = strconv.FormatInt(int64(intVal), 10) - case int8: - intVal, _ := value.(int8) - val = strconv.FormatInt(int64(intVal), 10) - case int16: - intVal, _ := value.(int16) - val = strconv.FormatInt(int64(intVal), 10) - case int32: - intVal, _ := value.(int32) - val = strconv.FormatInt(int64(intVal), 10) - case int64: - intVal, _ := value.(int64) - val = strconv.FormatInt(int64(intVal), 10) - case uint: - intVal, _ := value.(uint) - val = strconv.FormatUint(uint64(intVal), 10) - case uint8: - intVal, _ := value.(uint8) - val = strconv.FormatUint(uint64(intVal), 10) - case uint16: - intVal, _ := value.(uint16) - val = strconv.FormatUint(uint64(intVal), 10) - case uint32: - intVal, _ := value.(uint32) - val = strconv.FormatUint(uint64(intVal), 10) - case uint64: - intVal, _ := value.(uint64) - val = strconv.FormatUint(intVal, 10) - case float32: - floatVal, _ := value.(float32) - val = strconv.FormatFloat(float64(floatVal), 'f', -1, 32) - case float64: - floatVal, _ := value.(float64) - val = strconv.FormatFloat(floatVal, 'f', -1, 64) - } - return val, true -} diff --git a/vendor/go.dtapp.net/gostring/version.go b/vendor/go.dtapp.net/gostring/version.go deleted file mode 100644 index e38a843..0000000 --- a/vendor/go.dtapp.net/gostring/version.go +++ /dev/null @@ -1,3 +0,0 @@ -package gostring - -const Version = "1.0.5" diff --git a/vendor/modules.txt b/vendor/modules.txt index a7865ec..9205f18 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,3 +1,9 @@ -# go.dtapp.net/gostring v1.0.5 +# go.dtapp.net/gorandom v1.0.1 +## explicit; go 1.18 +go.dtapp.net/gorandom +# go.dtapp.net/gostring v1.0.10 ## explicit; go 1.18 go.dtapp.net/gostring +# go.dtapp.net/gotime v1.0.5 +## explicit; go 1.18 +go.dtapp.net/gotime diff --git a/version.go b/version.go index cc27fe2..770580d 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package gophp -const Version = "1.0.1" +const Version = "1.0.2"