⚡️ Only compile regexes once
This commit is contained in:
parent
f0ee52b3ef
commit
a0e81c1082
1 changed files with 4 additions and 3 deletions
|
|
@ -11,6 +11,10 @@ func ParseBytes(in []byte) any {
|
|||
return ParseString(string(in))
|
||||
}
|
||||
|
||||
var 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)$")
|
||||
var yes = regexp.MustCompile("^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$")
|
||||
var null = regexp.MustCompile("^(~|null|Null|NULL|none|None|NONE|nil|Nil|NIL)$")
|
||||
|
||||
func ParseString(in string) any {
|
||||
s := strings.TrimSpace(in)
|
||||
if s == "" {
|
||||
|
|
@ -21,9 +25,6 @@ func ParseString(in string) any {
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue