-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers_special.go
148 lines (117 loc) · 2.9 KB
/
helpers_special.go
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
package pprnt
import (
"fmt"
"reflect"
)
func _PrintSpecialInitSetup(str, lvlStr string, key *string, initSetupChar string) (string, *string) {
if key != nil {
str += lvlStr + "\"" + *key + "\"" + ": "
key = nil
} else {
str += lvlStr
}
str += initSetupChar + "\n"
fmt.Print(str)
return str, key
}
func _PrintSpecialEndSetup(_, lvlStr string, endChar *string, endSetupChar string) string {
finalStrToPrint := lvlStr + endSetupChar
if _state.Level > 0 {
finalStrToPrint += ","
}
if endChar != nil {
finalStrToPrint += *endChar
} else {
finalStrToPrint += "\n"
}
return finalStrToPrint
}
func _PrintSliceOrArray(arg interface{}, key, endChar *string) string {
str := ""
lvlStr := _CreateLevelString()
// Initial Setup
str, key = _PrintSpecialInitSetup(str, lvlStr, key, "[")
_state.Level++
// Processing each element
items := reflect.ValueOf(arg)
items = reflect.Indirect(items)
for i := 0; i < items.Len(); i++ {
item := items.Index(i)
item = reflect.Indirect(item)
var value interface{}
if item.CanInterface() {
if item.IsZero() {
value = nil
} else {
value = item.Interface()
}
} else {
value = nil
}
str += _ProcessArchitecture(value, key, endChar)
}
// Final Setup
_state.Level--
finalStrToPrint := _PrintSpecialEndSetup(str, lvlStr, endChar, "]")
str += finalStrToPrint
fmt.Print(finalStrToPrint)
return str
}
func _PrintMap(arg interface{}, key, endChar *string) string {
lvlStr := _CreateLevelString()
str := ""
// Initial Setup
str, _ = _PrintSpecialInitSetup(str, lvlStr, key, "{")
_state.Level++
// Processing each element
mapObj := reflect.ValueOf(arg)
for _, key := range mapObj.MapKeys() {
var value interface{}
if mapObj.MapIndex(key).CanInterface() {
if mapObj.MapIndex(key).IsZero() {
value = nil
} else {
value = mapObj.MapIndex(key).Interface()
}
} else {
value = nil
}
str += _ProcessArchitecture(value,
GetStringAdddress(key.String()),
endChar)
}
// Final Setup
_state.Level--
finalStrToPrint := _PrintSpecialEndSetup(str, lvlStr, endChar, "}")
str += finalStrToPrint
fmt.Print(finalStrToPrint)
return str
}
func _PrintStruct(arg interface{}, key, endChar *string) string {
lvlStr := _CreateLevelString()
str := ""
// Initial Setup
str, _ = _PrintSpecialInitSetup(str, lvlStr, key, "{")
_state.Level++
// Processing each element
structValues := reflect.ValueOf(arg)
structValues = reflect.Indirect(structValues)
for j := 0; j < structValues.NumField(); j++ {
field := structValues.Field(j)
var value interface{}
if field.CanInterface() {
value = field.Interface()
} else {
value = nil
}
str += _ProcessArchitecture(value,
GetStringAdddress(structValues.Type().Field(j).Name),
endChar)
}
// Final Setup
_state.Level--
finalStrToPrint := _PrintSpecialEndSetup(str, lvlStr, endChar, "}")
str += finalStrToPrint
fmt.Print(finalStrToPrint)
return str
}