6 * Joao Matos (joao.matos@xamarin.com)
8 * Copyright 2015 Xamarin Inc (http://www.xamarin.com)
9 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
12 #include <mono/utils/json.h>
14 void mono_json_writer_init (JsonWriter* writer)
16 g_assert (writer && "Expected a valid JSON writer instance");
18 writer->text = g_string_new ("");
22 void mono_json_writer_destroy (JsonWriter* writer)
24 g_assert (writer && "Expected a valid JSON writer instance");
25 g_string_free (writer->text, /*free_segment=*/TRUE);
28 void mono_json_writer_indent_push(JsonWriter* writer)
30 g_assert (writer && "Expected a valid JSON writer instance");
31 writer->indent += JSON_INDENT_VALUE;
34 void mono_json_writer_indent_pop(JsonWriter* writer)
36 g_assert (writer && "Expected a valid JSON writer instance");
37 writer->indent -= JSON_INDENT_VALUE;
40 void mono_json_writer_indent(JsonWriter* writer)
42 g_assert (writer && "Expected a valid JSON writer instance");
45 for (i = 0; i < writer->indent; ++i)
46 g_string_append_c (writer->text, ' ');
49 void mono_json_writer_vprintf(JsonWriter* writer, const gchar *format, va_list args)
51 g_assert (writer && "Expected a valid JSON writer instance");
52 g_string_append_vprintf (writer->text, format, args);
55 void mono_json_writer_printf(JsonWriter* writer, const gchar *format, ...)
57 g_assert (writer && "Expected a valid JSON writer instance");
60 va_start (args, format);
62 g_string_append_vprintf (writer->text, format, args);
67 void mono_json_writer_array_begin(JsonWriter* writer)
69 g_assert (writer && "Expected a valid JSON writer instance");
70 g_string_append_printf (writer->text, "[\n");
71 writer->indent += JSON_INDENT_VALUE;
74 void mono_json_writer_array_end(JsonWriter* writer)
76 g_assert (writer && "Expected a valid JSON writer instance");
77 g_string_append_printf (writer->text, "]");
78 writer->indent -= JSON_INDENT_VALUE;
81 void mono_json_writer_object_begin(JsonWriter* writer)
83 g_assert (writer && "Expected a valid JSON writer instance");
84 mono_json_writer_printf (writer, "{\n");
85 writer->indent += JSON_INDENT_VALUE;
88 void mono_json_writer_object_end(JsonWriter* writer)
90 g_assert (writer && "Expected a valid JSON writer instance");
91 mono_json_writer_printf (writer, "}");
94 void mono_json_writer_object_key(JsonWriter* writer, const gchar* format, ...)
96 g_assert (writer && "Expected a valid JSON writer instance");
99 va_start (args, format);
101 g_string_append_printf (writer->text, "\"");
102 mono_json_writer_vprintf (writer, format, args);
103 g_string_append_printf (writer->text, "\" : ");