-
Notifications
You must be signed in to change notification settings - Fork 2
/
JSONFormatRatliff.cls
149 lines (118 loc) · 4.01 KB
/
JSONFormatRatliff.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "JSONFormatRatliff"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Implements JSONFormat
Dim mIndentString As String
Dim mIndentStack As JSONIndentStack
Private Sub Class_Initialize()
Call Reset
End Sub
Public Sub Reset()
Set mIndentStack = New JSONIndentStack
JSONFormat_IndentString = " "
End Sub
Public Property Get JSONFormat_IndentString() As String
JSONFormat_IndentString = ""
End Property
Public Property Let JSONFormat_IndentString(Value As String)
mIndentString = Value
mIndentStack.IndentString = mIndentString
End Property
Public Sub JSONFormat_ObjectStart(Output As JSONOutput, Item As JSONItem)
mIndentStack.ObjectStart
Output.WriteText "{"
End Sub
Public Sub JSONFormat_ObjectItemStart(Output As JSONOutput, Item As JSONItem, IsFirstItem As Boolean)
Output.CrLf
Output.WriteText mIndentStack.IndentText
End Sub
Public Sub JSONFormat_ObjectItemKeyStart(Output As JSONOutput, Item As JSONItem)
' empty
End Sub
Public Sub JSONFormat_ObjectItemKeyWrite(Output As JSONOutput, Item As JSONItem, Key As String)
Output.WriteText Key
End Sub
Public Sub JSONFormat_ObjectItemKeyEnd(Output As JSONOutput, Item As JSONItem)
' empty
End Sub
Public Sub JSONFormat_ObjectItemColonWrite(Output As JSONOutput, Item As JSONItem)
Output.WriteText ": "
End Sub
Public Sub JSONFormat_ObjectItemValueStart(Output As JSONOutput, Item As JSONItem)
' empty
End Sub
Public Sub JSONFormat_ObjectItemValueWrite(Output As JSONOutput, Item As JSONItem, Value As String)
Output.WriteText Value
End Sub
Public Sub JSONFormat_ObjectItemValueEnd(Output As JSONOutput, Item As JSONItem)
' empty
End Sub
Public Sub JSONFormat_ObjectItemEnd(Output As JSONOutput, Item As JSONItem, IsLastItem As Boolean)
' empty
End Sub
Public Sub JSONFormat_ObjectItemCommaWrite(Output As JSONOutput, Item As JSONItem)
Output.WriteText ","
End Sub
Public Sub JSONFormat_ObjectEnd(Output As JSONOutput, Item As JSONItem)
Output.CrLf
If Not Item.Parent Is Nothing Then
If Item.Parent.IsJsArray Then
Output.WriteText mIndentStack.OutdentText
Else
Output.WriteLine mIndentStack.IndentText
End If
End If
Output.WriteText "}"
mIndentStack.ObjectEnd
End Sub
Public Sub JSONFormat_ArrayStart(Output As JSONOutput, Item As JSONItem)
mIndentStack.ArrayStart
Output.WriteText "["
End Sub
Public Sub JSONFormat_ArrayItemStart(Output As JSONOutput, Item As JSONItem, IsFirstItem As Boolean)
Output.CrLf
Output.WriteText mIndentStack.IndentText
End Sub
Public Sub JSONFormat_ArrayItemValueStart(Output As JSONOutput, Item As JSONItem)
' empty
End Sub
Public Sub JSONFormat_ArrayItemValueWrite(Output As JSONOutput, Item As JSONItem, Value As String)
Output.WriteText Value
End Sub
Public Sub JSONFormat_ArrayItemCommaWrite(Output As JSONOutput, Item As JSONItem)
Output.WriteText ","
End Sub
Public Sub JSONFormat_ArrayItemValueEnd(Output As JSONOutput, Item As JSONItem)
' empty
End Sub
Public Sub JSONFormat_ArrayItemEnd(Output As JSONOutput, Item As JSONItem, IsLastItem As Boolean)
' empty
End Sub
Public Sub JSONFormat_ArrayEnd(Output As JSONOutput, Item As JSONItem)
Output.CrLf
If Not Item.Parent Is Nothing Then
If Item.Parent.IsJsArray Then
Output.WriteText mIndentStack.OutdentText
Else
Output.WriteLine mIndentStack.IndentText
End If
End If
Output.WriteText "]"
mIndentStack.ArrayEnd
End Sub
Public Sub JSONFormat_ObjectEmpty(Output As JSONOutput)
Output.WriteText "{ }"
End Sub
Public Sub JSONFormat_ArrayEmpty(Output As JSONOutput)
Output.WriteText "[ ]"
End Sub
Public Sub JSONFormat_CrLf(Output As JSONOutput)
Output.CrLf
End Sub