File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -198,3 +198,29 @@ func (jv *Jv) ToGoVal() interface{} {
198
198
panic (fmt .Sprintf ("Unknown JV kind %d" , kind ))
199
199
}
200
200
}
201
+
202
+ type JvPrintFlags int
203
+
204
+ const (
205
+ JvPrintNone JvPrintFlags = 0 // None of the below
206
+ JvPrintPretty JvPrintFlags = C .JV_PRINT_PRETTY // Print across multiple lines
207
+ JvPrintAscii JvPrintFlags = C .JV_PRINT_ASCII // Escape non-ascii printable characters
208
+ JvPrintColour JvPrintFlags = C .JV_PRINT_COLOUR // Include ANSI color escapes based on data types
209
+ JvPrintSorted JvPrintFlags = C .JV_PRINT_SORTED // Sort output keys
210
+ JvPrintInvalid JvPrintFlags = C .JV_PRINT_INVALID // Print invalid as "<invalid>"
211
+ JvPrintRefCount JvPrintFlags = C .JV_PRINT_REFCOUNT // Display refcount of objects in in parenthesis
212
+ JvPrintTab JvPrintFlags = C .JV_PRINT_TAB // Indent with tabs,
213
+ JvPrintIsATty JvPrintFlags = C .JV_PRINT_ISATTY //
214
+ JvPrintSpace0 JvPrintFlags = C .JV_PRINT_SPACE0 // Indent with zero extra chars beyond the parent bracket
215
+ JvPrintSpace1 JvPrintFlags = C .JV_PRINT_SPACE1 // Indent with zero extra chars beyond the parent bracket
216
+ JvPrintSpace2 JvPrintFlags = C .JV_PRINT_SPACE2 // Indent with zero extra chars beyond the parent bracket
217
+ )
218
+
219
+ // Dump produces a human readable version of the string with the requested formatting.
220
+ //
221
+ // Consumes the invocant
222
+ func (jv * Jv ) Dump (flags JvPrintFlags ) string {
223
+ jv_str := Jv {C .jv_dump_string (jv .jv , C .int (flags ))}
224
+ defer jv_str .Free ()
225
+ return jv_str ._string ()
226
+ }
Original file line number Diff line number Diff line change @@ -65,3 +65,17 @@ func TestJvFromJSONString(t *testing.T) {
65
65
is .Err (err )
66
66
is .Nil (jv )
67
67
}
68
+
69
+ func TestJvDump (t * testing.T ) {
70
+ is := is .New (t )
71
+
72
+ jv := jq .JvFromString ("test" )
73
+ defer jv .Free ()
74
+
75
+ dump := jv .Copy ().Dump (jq .JvPrintNone )
76
+
77
+ is .Equal (`"test"` , dump )
78
+ dump = jv .Copy ().Dump (jq .JvPrintColour )
79
+
80
+ is .Equal ([]byte ("\x1b [0;32m" + `"test"` + "\x1b [0m" ), []byte (dump ))
81
+ }
You can’t perform that action at this time.
0 commit comments