Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
286e5e7317 | ||
|
|
0d9b520680 | ||
|
|
879606d0ef | ||
|
|
7140e29b9e | ||
|
|
b3a4b5f13a |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
||||
.gemini/
|
||||
.ai/
|
||||
.geminiignore
|
||||
.gemini
|
||||
/CODE-FULL.md
|
||||
|
||||
14
README.md
14
README.md
@ -77,13 +77,23 @@ list, _ := cast.ToSlice[int]([]string{"1", "2", "3"})
|
||||
* `Ptr[T any](T) *T` —— 快速取指针。
|
||||
* `ArrayToBoolMap[T comparable]([]T) map[T]bool` —— 快速构建索引 Map。
|
||||
|
||||
6. **基础转换 (直接调用,极致性能)**
|
||||
6. **基础转换与时间 (直接调用,极致性能)**
|
||||
* `Int`, `Int64`, `Uint`, `Uint64`, `Float`, `Float64`, `String`, `Bool`, `Duration`
|
||||
* `RealValue(reflect.Value) reflect.Value` —— 递归获取指针或接口下的真实值。
|
||||
* `ParseTime(any) time.Time` —— 强大的时间解析,支持时间戳、RFC3339、JS 格式、紧凑格式及中文日期。
|
||||
* `FormatTime(layout, any) string` —— 直观格式化(如 YYYY-MM-DD HH:mm:ss)。
|
||||
* `AddTime(expr, any) time.Time` —— DSL 时间计算(如 +1Y-2M+3D)。
|
||||
* `DescribeDuration(time.Duration) string` —— 将时长转化为自然语言描述(如 1h 5m)。
|
||||
|
||||
7. **时区支持**
|
||||
7. **字符串与参数处理**
|
||||
* `Split(s, sep string) []string` —— 增强型分割,自动 Trim 并过滤空字符串。
|
||||
* `SplitArgs(string) []string` —— 命令行参数分割,支持引号与转义。
|
||||
* `JoinArgs([]string, sep string) string` —— 命令行参数合并,自动处理引号与转义。
|
||||
* `UniqueAppend(to []string, from ...any) []string` —— 去重追加。
|
||||
* `GetLowerName(string) string` | `GetUpperName(string) string` —— 首字母大小写转换工具。
|
||||
* `FixUpperCase([]byte, []string)` —— 针对 JSON Key 的特殊大小写修复工具。
|
||||
|
||||
8. **时区支持**
|
||||
* `DefaultTimeZone` —— 全局默认时区上下文。
|
||||
* `SetDefaultTimeZone(*time.Location)` —— 修改全局默认时区(影响所有 Convert 与 ToTime 操作)。
|
||||
* `DefaultTimeZone.Now()` —— 获取时区上下文下的当前时间。
|
||||
|
||||
12
cast.go
12
cast.go
@ -527,6 +527,12 @@ func isComplexValue(v any) bool {
|
||||
}
|
||||
|
||||
func parseInt(s string) int64 {
|
||||
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
|
||||
i, err := strconv.ParseInt(s, 0, 64)
|
||||
if err == nil {
|
||||
return i
|
||||
}
|
||||
}
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
if err == nil {
|
||||
return i
|
||||
@ -538,6 +544,12 @@ func parseInt(s string) int64 {
|
||||
}
|
||||
|
||||
func parseUint(s string) uint64 {
|
||||
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
|
||||
i, err := strconv.ParseUint(s, 0, 64)
|
||||
if err == nil {
|
||||
return i
|
||||
}
|
||||
}
|
||||
i, err := strconv.ParseUint(s, 10, 64)
|
||||
if err == nil {
|
||||
return i
|
||||
|
||||
@ -445,7 +445,10 @@ func getDecoderFieldMap(reflectType reflect.Type) *decoderStructDescriptor {
|
||||
|
||||
// 1. Tag
|
||||
tag := field.Tag.Get("json")
|
||||
if tag != "" && tag != "-" {
|
||||
if tag == "-" {
|
||||
continue
|
||||
}
|
||||
if tag != "" {
|
||||
parts := strings.Split(tag, ",")
|
||||
tagName := parts[0]
|
||||
for _, part := range parts {
|
||||
|
||||
@ -217,9 +217,12 @@ func getEncoderStructDescriptor(reflectType reflect.Type) *encoderStructDescript
|
||||
}
|
||||
|
||||
tag := field.Tag.Get("json")
|
||||
if tag == "-" {
|
||||
continue
|
||||
}
|
||||
fieldDesc.keepKey = strings.Contains(string(field.Tag), "keepKey")
|
||||
|
||||
if tag != "" && tag != "-" {
|
||||
if tag != "" {
|
||||
parts := strings.Split(tag, ",")
|
||||
for _, part := range parts {
|
||||
if strings.HasPrefix(part, "format=") {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user