1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-07 22:22:29 +08:00

feat: add SubInBetween

This commit is contained in:
dudaodong
2024-02-06 17:13:00 +08:00
parent 0fc8733915
commit f82f49a4c2
3 changed files with 69 additions and 5 deletions

View File

@@ -5,7 +5,6 @@
package strutil
import (
"reflect"
"regexp"
"strings"
"unicode"
@@ -350,10 +349,7 @@ func RemoveNonPrintable(str string) string {
// StringToBytes converts a string to byte slice without a memory allocation.
func StringToBytes(str string) (b []byte) {
sh := *(*reflect.StringHeader)(unsafe.Pointer(&str))
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
bh.Data, bh.Len, bh.Cap = sh.Data, sh.Len, sh.Len
return b
return *(*[]byte)(unsafe.Pointer(&str))
}
// BytesToString converts a byte slice to string without a memory allocation.