package tools import ( "encoding/json" "regexp" "strconv" "strings" ) func ParseBytes(in []byte) any { return ParseString(string(in)) } func ParseString(in string) any { s := strings.TrimSpace(in) if s == "" { return s } if strings.HasPrefix(s, "!") { return s } yesno := regexp.MustCompile("^(y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$") yes := regexp.MustCompile("^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$") null := regexp.MustCompile("^(~|null|Null|NULL|none|None|NONE|nil|Nil|NIL)$") var j json.RawMessage if null.MatchString(s) { return nil } else if yesno.MatchString(s) { return yes.MatchString(s) } else if i, err := strconv.Atoi(s); err == nil { return i } else if f, err := strconv.ParseFloat(s, 64); err == nil { return f } else if t, err := ParseDate(s); err == nil { return t } else if err := json.Unmarshal([]byte(s), &j); err == nil { return j } return s }