2023-05-05 13:43:33 +08:00
|
|
|
// Package wrapper ...
|
|
|
|
//
|
|
|
|
// Description : wrapper ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2023-05-05 11:59
|
|
|
|
package wrapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"git.zhangdeman.cn/zhangdeman/util"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// String 字符串类型包装
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 12:07 2023/5/5
|
|
|
|
type String string
|
|
|
|
|
|
|
|
// ToFloat32 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:26 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToFloat32() Float32Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res Float32Result
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToFloat64 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:26 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToFloat64() Float64Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res Float64Result
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToDouble 转double
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:33 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToDouble() Float64Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
return str.ToFloat64()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToNumber 转数字, 使用最高精度的float64
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:33 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToNumber() Float64Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
return str.ToFloat64()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToInt8 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:29 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToInt8() Int8Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res Int8Result
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToInt16 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:29 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToInt16() Int16Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res Int16Result
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToInt32 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:29 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToInt32() Int32Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res Int32Result
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToInt64 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:29 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToInt64() Int64Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res Int64Result
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToInt ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:47 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToInt() IntResult {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res IntResult
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToUint8 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:30 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToUint8() Uint8Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res Uint8Result
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToUint16 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:29 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToUint16() Uint16Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res Uint16Result
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToUint32 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:29 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToUint32() Uint32Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res Uint32Result
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToUint64 ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:29 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToUint64() Uint64Result {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res Uint64Result
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToUint ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:29 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToUint() UintResult {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res UintResult
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToBool ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:34 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToBool() BoolResult {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res BoolResult
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.ConvertAssign(&res.Value, str)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToObject ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:35 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToObject() ObjectResult {
|
2023-05-05 13:43:33 +08:00
|
|
|
var (
|
2023-05-08 18:29:48 +08:00
|
|
|
res = ObjectResult{
|
|
|
|
Value: map[string]interface{}{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
)
|
2023-05-08 18:29:48 +08:00
|
|
|
res.Err = util.JSON.UnmarshalWithNumber([]byte(str), &res.Value)
|
|
|
|
return res
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToStruct ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:38 2023/5/4
|
|
|
|
func (str String) ToStruct(receiver interface{}) error {
|
|
|
|
if nil == receiver {
|
|
|
|
return errors.New("receiver is nil")
|
|
|
|
}
|
|
|
|
return util.JSON.UnmarshalWithNumber([]byte(str), receiver)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToInt8Slice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:55 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToInt8Slice(splitChar ...string) Int8SliceResult {
|
|
|
|
result := Int8SliceResult{
|
|
|
|
Value: []int8{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
var (
|
|
|
|
res = make([]int8, 0)
|
|
|
|
)
|
|
|
|
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToInt8(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToInt16Slice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 19:01 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToInt16Slice(splitChar ...string) Int16SliceResult {
|
|
|
|
|
|
|
|
result := Int16SliceResult{
|
|
|
|
Value: []int16{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]int16, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToInt16(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToInt32Slice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 19:03 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToInt32Slice(splitChar ...string) Int32SliceResult {
|
|
|
|
result := Int32SliceResult{
|
|
|
|
Value: []int32{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]int32, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToInt32(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToInt64Slice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 19:04 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToInt64Slice(splitChar ...string) Int64SliceResult {
|
|
|
|
result := Int64SliceResult{
|
|
|
|
Value: []int64{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]int64, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToInt64(); nil != itemVal.Err {
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToIntSlice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 19:04 2023/5/4
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToIntSlice(splitChar ...string) IntSliceResult {
|
|
|
|
result := IntSliceResult{
|
|
|
|
Value: []int{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]int, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToInt(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToUint8Slice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:50 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToUint8Slice(splitChar ...string) Uint8SliceResult {
|
|
|
|
result := Uint8SliceResult{
|
|
|
|
Value: []uint8{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]uint8, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToUint8(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToUint16Slice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:52 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToUint16Slice(splitChar ...string) Uint16SliceResult {
|
|
|
|
result := Uint16SliceResult{
|
|
|
|
Value: []uint16{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]uint16, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToUint16(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToUint32Slice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:53 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToUint32Slice(splitChar ...string) Uint32SliceResult {
|
|
|
|
result := Uint32SliceResult{
|
|
|
|
Value: []uint32{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]uint32, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToUint32(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToUint64Slice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:54 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToUint64Slice(splitChar ...string) Uint64SliceResult {
|
|
|
|
result := Uint64SliceResult{
|
|
|
|
Value: []uint64{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]uint64, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToUint64(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToUintSlice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:54 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToUintSlice(splitChar ...string) UintSliceResult {
|
|
|
|
result := UintSliceResult{
|
|
|
|
Value: []uint{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]uint, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToUint(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToBoolSlice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:55 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToBoolSlice(splitChar ...string) BoolSliceResult {
|
|
|
|
result := BoolSliceResult{
|
|
|
|
Value: []bool{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]bool, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToBool(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToFloat32Slice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:56 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToFloat32Slice(splitChar ...string) Float32SliceResult {
|
|
|
|
result := Float32SliceResult{
|
|
|
|
Value: []float32{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]float32, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToFloat32(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToFloat64Slice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:56 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToFloat64Slice(splitChar ...string) Float64SliceResult {
|
|
|
|
result := Float64SliceResult{
|
|
|
|
Value: []float64{},
|
|
|
|
Err: nil,
|
|
|
|
}
|
2023-05-05 13:43:33 +08:00
|
|
|
|
|
|
|
isSplit := len(splitChar) > 0
|
|
|
|
if !isSplit {
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
res := make([]float64, 0)
|
2023-05-05 13:43:33 +08:00
|
|
|
arr := strings.Split(string(str), splitChar[0])
|
|
|
|
for _, item := range arr {
|
2023-05-08 18:29:48 +08:00
|
|
|
if itemVal := String(item).ToFloat64(); nil != itemVal.Err {
|
|
|
|
result.Err = itemVal.Err
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
} else {
|
2023-05-08 18:29:48 +08:00
|
|
|
res = append(res, itemVal.Value)
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
result.Value = res
|
|
|
|
return result
|
2023-05-05 13:43:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToDoubleSlice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:57 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToDoubleSlice(splitChar ...string) Float64SliceResult {
|
2023-05-05 13:43:33 +08:00
|
|
|
return str.ToFloat64Slice(splitChar...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToNumberSlice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 10:57 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToNumberSlice(splitChar ...string) Float64SliceResult {
|
2023-05-05 13:43:33 +08:00
|
|
|
return str.ToFloat64Slice(splitChar...)
|
|
|
|
}
|
2023-05-05 15:02:45 +08:00
|
|
|
|
|
|
|
// ToAnySlice ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 15:01 2023/5/5
|
2023-05-08 18:29:48 +08:00
|
|
|
func (str String) ToAnySlice() AnySliceResult {
|
|
|
|
result := AnySliceResult{
|
|
|
|
Value: []interface{}{},
|
|
|
|
Err: nil,
|
2023-05-05 15:02:45 +08:00
|
|
|
}
|
2023-05-08 18:29:48 +08:00
|
|
|
|
|
|
|
result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value)
|
|
|
|
return result
|
2023-05-05 15:02:45 +08:00
|
|
|
}
|