Subversion Repositories DevTools

Rev

Rev 4253 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'=====================================================
'   DictDump
'   Pretty display of a Dictionary Item
'=====================================================


Private DICToutput_level
Public Function DICToutput(data)
    DICToutput_level = 1
    DICToutput = "{" & Chr(13) & Chr(10) & GetDict(data) & "}"
End Function

Private Function GetDict(objDict)
    dim aj_item, aj_keyvals, aj_label, aj_dicttype
    For Each aj_item In objDict
        Select Case TypeName(objDict.Item(aj_item))
            Case "Dictionary"
                GetDict = GetDict & Space(DICToutput_level * 4)
                
                aj_dicttype = "[]"
                For Each aj_label In objDict.Item(aj_item).Keys
                     If Not IsInt(aj_label) Then aj_dicttype = "{}"
                Next

                If IsInt(aj_item) Then
                    GetDict = GetDict & Left(aj_dicttype,1) & Chr(13) & Chr(10)
                Else
                    GetDict = GetDict & """" & aj_DICTEncode(aj_item) & """" & ": " & Left(aj_dicttype,1) & Chr(13) & Chr(10)
                End If
                DICToutput_level = DICToutput_level + 1
                
                aj_keyvals = objDict.Keys
                GetDict = GetDict & GetSubDict(objDict.Item(aj_item)) & Space(DICToutput_level * 4) & Right(aj_dicttype,1) & aj_InlineIf(aj_item = aj_keyvals(objDict.Count - 1),"" , ",") & Chr(13) & Chr(10)
            Case Else
                aj_keyvals =  objDict.Keys
                GetDict = GetDict & Space(DICToutput_level * 4) & aj_InlineIf(IsInt(aj_item), "", """" & aj_DICTEncode(aj_item) & """: ") & WriteValue(objDict.Item(aj_item)) & aj_InlineIf(aj_item = aj_keyvals(objDict.Count - 1),"" , ",") & Chr(13) & Chr(10)
        End Select
    Next
End Function

Private Function IsInt(val)
    IsInt = (TypeName(val) = "Integer" Or TypeName(val) = "Long")
End Function

Private Function GetSubDict(objSubDict)
    GetSubDict = GetDict(objSubDict)
    DICToutput_level= DICToutput_level -1
End Function

Private Function WriteValue(ByVal val)
    Select Case TypeName(val)
        Case "Double", "Integer", "Long": WriteValue = val
        Case "Null"                                             : WriteValue = "null"
        Case "Boolean"                                  : WriteValue = aj_InlineIf(val, "true", "false")
        Case Else                                               : WriteValue = """" & aj_DICTEncode(val) & """"
    End Select
End Function

Private Function aj_DICTEncode(ByVal val)
    val = Replace(val, "\", "\\")
    val = Replace(val, """", "\""")
    'val = Replace(val, "/", "\/")
    val = Replace(val, Chr(8), "\b")
    val = Replace(val, Chr(12), "\f")
    val = Replace(val, Chr(10), "\n")
    val = Replace(val, Chr(13), "\r")
    val = Replace(val, Chr(9), "\t")
    aj_DICTEncode = Trim(val)
End Function

Private Function aj_InlineIf(condition, returntrue, returnfalse)
    If condition Then aj_InlineIf = returntrue Else aj_InlineIf = returnfalse
End Function