Created
June 11, 2020 14:00
-
-
Save G33kDude/b12aae376d3f9dbdd857e1d92b166dc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Print(obj, quote:=False, end:="`n") | |
{ | |
static cout:=FileOpen("*", "w") | |
, escapes := [["``", "``" "``"], ["""", """"""], ["`b", "``b"] | |
, ["`f", "``f"], ["`r", "``r"], ["`n", "``n"], ["`t", "``t"]] | |
if IsObject(obj) | |
{ | |
for k in obj | |
is_array := k == A_Index | |
until !is_array | |
cout.Write(is_array ? "[" : "{") | |
for k, v in obj | |
{ | |
cout.Write(A_Index > 1 ? ", " : "") | |
is_array ? _ : Print(k, 1, "") cout.Write(": ") | |
Print(v, 1, "") | |
} | |
return cout.Write(( is_array ? "]" : "}") end), end ? cout.__Handle : _ | |
} | |
if (!quote || ObjGetCapacity([obj], 1) == "") | |
return cout.Write(obj . end), end ? cout.__Handle : _ | |
for k, v in escapes | |
obj := StrReplace(obj, v[1], v[2]) | |
while RegExMatch(obj, "O)[^\\x20-\\x7e]", m) | |
obj := StrReplace(obj, m[0], Format("\\u{:04X}", Ord(m[0]))) | |
return cout.Write("""" obj """" . end), end ? cout.__Handle : _ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added to my Libs. 👍