Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ConsoleWriteArray(ByRef $a, $nl = True, $nlOnNewEle = False, $indentForNewEle = " ", $out = True)
- ; Writes an array to the console
- ; Params
- ; $a - The array to write
- ; $nl - Whether to add a new line at the end
- ; $nlOnNewEle - Whether to pretty print the array
- ; $indentForNewEle - Indent for next element, indent stacks up if pretty print is enabled
- ; $out - RESERVED FOR INTERNAL USE
- ; Returns
- ; 1. Nothing - If variable isn't an array
- ; 2. The original array passed in - If variable is an array
- ; - Enables chaining for easy debug use
- ; e.g. ConsoleWrite("Customer ID: " & $array[2][3])
- ; => ConsoleWrite("Customer ID: " & ConsoleWriteArray($array)[2][3])
- Func ConsoleWriteArray(ByRef $a, $nl = True, $nlOnNewEle = False, $indentForNewEle = " ", $out = True)
- If Not IsArray($a) Then
- Return
- EndIf
- Local $dims = UBound($a, 0)
- Local $s = ""
- $s &= "{"
- ConsoleWriteArray_internal($s, $a, 1, $dims, "", $nlOnNewEle, $indentForNewEle)
- $s &= "}"
- If $nl Then
- $s &= @CRLF
- EndIf
- If $out Then
- ConsoleWrite($s)
- Return $a
- Else
- Return $s
- EndIf
- EndFunc
- Func ConsoleWriteArray_internal(ByRef $s, ByRef $a, $dim, $dims, $ref, $nlOnNewEle, $indentForNewEle)
- Local $count = UBound($a, $dim)
- If $dim = $dims Then
- Local $ele
- For $i = 0 To $count - 1
- $ele = Execute("$a" & $ref & "[" & $i & "]")
- Switch VarGetType($ele)
- Case "Double"
- $s &= $ele
- If Not IsFloat($ele) Then
- $s &= ".0"
- EndIf
- Case "String"
- $s &= '"' & $ele & '"'
- Case "Array"
- $s &= ConsoleWriteArray($ele, False, False, " ", False)
- Case "Map"
- $s &= "Map"
- Case "Object"
- $s &= ObjName($ele)
- Case "DLLStruct"
- $s &= "Struct"
- Case "Keyword"
- If IsKeyword($ele) = 2 Then
- $s &= "Null"
- Else
- $s &= $ele
- EndIf
- Case "Function"
- $s &= FuncName($ele) & "()"
- Case "UserFunction"
- $s &= FuncName($ele) & "()"
- Case Else
- $s &= $ele
- EndSwitch
- If $i < $count - 1 Then
- $s &= "," & $indentForNewEle
- EndIf
- Next
- Else
- Local $indent = $indentForNewEle
- If $nlOnNewEle Then
- $indent = ""
- Local $indentBuf = $indentForNewEle
- Local $repeatCount = $dim
- While $repeatCount > 1
- If BitAND($repeatCount, 1) Then
- $indent &= $indentBuf
- EndIf
- $indentBuf &= $indentBuf
- $repeatCount = BitShift($repeatCount, 1)
- WEnd
- $indent &= $indentBuf
- EndIf
- For $i = 0 To $count - 1
- If $nlOnNewEle Then
- $s &= @CRLF & $indent
- EndIf
- $s &= "["
- ConsoleWriteArray_internal($s, $a, $dim + 1, $dims, $ref & "[" & $i & "]", $nlOnNewEle, $indentForNewEle)
- If $nlOnNewEle And $dim + 1 < $dims Then
- $s &= @CRLF & $indent
- EndIf
- $s &= "]"
- If $i < $count - 1 Then
- $s &= "," & $indent
- EndIf
- Next
- If $nlOnNewEle And $dim = 1 Then
- $s &= @CRLF
- EndIf
- EndIf
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement