5 * Joao Matos (joao.matos@xamarin.com)
7 * Copyright 2015 Xamarin Inc (http://www.xamarin.com)
10 #include <mono/utils/json.h>
12 void mono_json_writer_init (JsonWriter* writer)
14 g_assert (writer && "Expected a valid JSON writer instance");
16 writer->text = g_string_new ("");
20 void mono_json_writer_destroy (JsonWriter* writer)
22 g_assert (writer && "Expected a valid JSON writer instance");
23 g_string_free (writer->text, /*free_segment=*/TRUE);
26 void mono_json_writer_indent_push(JsonWriter* writer)
28 g_assert (writer && "Expected a valid JSON writer instance");
29 writer->indent += JSON_INDENT_VALUE;
32 void mono_json_writer_indent_pop(JsonWriter* writer)
34 g_assert (writer && "Expected a valid JSON writer instance");
35 writer->indent -= JSON_INDENT_VALUE;
38 void mono_json_writer_indent(JsonWriter* writer)
40 g_assert (writer && "Expected a valid JSON writer instance");
43 for (i = 0; i < writer->indent; ++i)
44 g_string_append_c (writer->text, ' ');
47 void mono_json_writer_vprintf(JsonWriter* writer, const gchar *format, va_list args)
49 g_assert (writer && "Expected a valid JSON writer instance");
50 g_string_append_vprintf (writer->text, format, args);
53 void mono_json_writer_printf(JsonWriter* writer, const gchar *format, ...)
55 g_assert (writer && "Expected a valid JSON writer instance");
58 va_start (args, format);
60 g_string_append_vprintf (writer->text, format, args);
65 void mono_json_writer_array_begin(JsonWriter* writer)
67 g_assert (writer && "Expected a valid JSON writer instance");
68 g_string_append_printf (writer->text, "[\n");
69 writer->indent += JSON_INDENT_VALUE;
72 void mono_json_writer_array_end(JsonWriter* writer)
74 g_assert (writer && "Expected a valid JSON writer instance");
75 g_string_append_printf (writer->text, "]");
76 writer->indent -= JSON_INDENT_VALUE;
79 void mono_json_writer_object_begin(JsonWriter* writer)
81 g_assert (writer && "Expected a valid JSON writer instance");
82 mono_json_writer_printf (writer, "{\n");
83 writer->indent += JSON_INDENT_VALUE;
86 void mono_json_writer_object_end(JsonWriter* writer)
88 g_assert (writer && "Expected a valid JSON writer instance");
89 mono_json_writer_printf (writer, "}");
92 void mono_json_writer_object_key(JsonWriter* writer, const gchar* format, ...)
94 g_assert (writer && "Expected a valid JSON writer instance");
97 va_start (args, format);
99 g_string_append_printf (writer->text, "\"");
100 mono_json_writer_vprintf (writer, format, args);
101 g_string_append_printf (writer->text, "\" : ");