Skip to content

Instantly share code, notes, and snippets.

@G33kDude

G33kDude/Print.ahk

Created Jun 11, 2020
Embed
What would you like to do?
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 : _
}
@a-raccoon

This comment has been minimized.

Copy link

@a-raccoon a-raccoon commented Mar 27, 2021

Added to my Libs. 👍

; Print() by GeekDude 2020
; Explodes the contents of an object array into a printable string.
; https://gist.github.com/G33kDude/b12aae376d3f9dbdd857e1d92b166dc5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment