Skip to content

Commit

Permalink
Fixed thqby#42
Browse files Browse the repository at this point in the history
  • Loading branch information
thqby committed Jan 28, 2024
1 parent 4181ed5 commit a38622f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions JSON.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @description: JSON格式字符串序列化和反序列化, 修改自[HotKeyIt/Yaml](https://github.com/HotKeyIt/Yaml)
* 增加了对true/false/null类型的支持, 保留了数值的类型
* @author thqby, HotKeyIt
* @date 2023/05/12
* @version 1.0.5
* @date 2024/01/28
* @version 1.0.6
***********************************************************************/
class JSON {
Expand All @@ -26,7 +26,7 @@ class JSON {
if !Q {
if (t := Trim(A_LoopField, " `t`r`n")) = "," || (t = ":" && V := 1)
continue
else if t && (InStr("{[]},:", SubStr(t, 1, 1)) || RegExMatch(t, "^-?\d*(\.\d*)?\s*[,\]\}]")) {
else if t && (InStr("{[]},:", SubStr(t, 1, 1)) || A && RegExMatch(t, "m)^(null|false|true|-?\d+(\.\d*(e[-+]\d+)?)?)\s*[,}\]\r\n]")) {
Loop Parse t {
if N && N--
continue
Expand All @@ -44,7 +44,7 @@ class JSON {
throw Error("Malformed JSON - to many closing brackets.", 0, t)
else C := --L = 0 ? "" : D[L], A := Type(C) = "Array"
} else if !(InStr(" `t`r,", A_LoopField) || (A_LoopField = ":" && V := 1)) {
if RegExMatch(SubStr(t, A_Index), "m)^(null|false|true|-?\d+\.?\d*)\s*[,}\]\r\n]", &R) && (N := R.Len(0) - 2, R := R.1, 1) {
if RegExMatch(SubStr(t, A_Index), "m)^(null|false|true|-?\d+(\.\d*(e[-+]\d+)?)?)\s*[,}\]\r\n]", &R) && (N := R.Len(0) - 2, R := R.1, 1) {
if A
C.Push(R = "null" ? _null : R = "true" ? _true : R = "false" ? _false : IsNumber(R) ? R + 0 : R)
else if V
Expand All @@ -64,12 +64,12 @@ class JSON {
if N
continue
}
throw Error("Malformed JSON - unrecognized character-", 0, A_LoopField " in " t)
throw Error("Malformed JSON - unrecognized character.", 0, A_LoopField " in " t)
}
}
}
} else if InStr(t, ':') > 1
throw Error("Malformed JSON - unrecognized character-", 0, SubStr(t, 1, 1) " in " t)
} else if A || InStr(t, ':') > 1
throw Error("Malformed JSON - unrecognized character.", 0, SubStr(t, 1, 1) " in " t)
} else if NQ && (P .= A_LoopField '"', 1)
continue
else if A
Expand Down
2 changes: 1 addition & 1 deletion YAML.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class YAML {
throw Error("Malformed JSON - to many closing brackets.", 0, t)
else C := --L = 0 ? "" : D[L], A := Type(C) = "Array"
} else if !(InStr(" `t`r,", A_LoopField) || (A_LoopField = ":" && V := 1)) {
if RegExMatch(SubStr(t, A_Index), "m)^(null|false|true|-?\d+\.?\d*)\s*[,}\]\r\n]", &R) && (N := R.Len(0) - 2, R := R.1, 1) {
if RegExMatch(SubStr(t, A_Index), "m)^(null|false|true|-?\d+(\.\d*(e[-+]\d+)?)?)\s*[,}\]\r\n]", &R) && (N := R.Len(0) - 2, R := R.1, 1) {
if A
C.Push(R = "null" ? _null : R = "true" ? _true : R = "false" ? _false : IsNumber(R) ? R + 0 : R)
else if V
Expand Down

0 comments on commit a38622f

Please sign in to comment.