[tools] Add nuget-hash-extractor tool to help produce the runtime ignored assemblies...
[mono-project.git] / mono / utils / json.c
blob331f9038081e178c45067a123ccedf5e4e9c9c01
1 /*
2 * json.c: JSON writer
4 * Author:
5 * Joao Matos (joao.matos@xamarin.com)
7 * Copyright 2015 Xamarin Inc (http://www.xamarin.com)
8 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
9 */
11 #include <mono/utils/json.h>
13 void mono_json_writer_init (JsonWriter* writer)
15 g_assert (writer && "Expected a valid JSON writer instance");
17 writer->text = g_string_new ("");
18 writer->indent = 0;
21 void mono_json_writer_destroy (JsonWriter* writer)
23 g_assert (writer && "Expected a valid JSON writer instance");
24 g_string_free (writer->text, /*free_segment=*/TRUE);
27 void mono_json_writer_indent_push(JsonWriter* writer)
29 g_assert (writer && "Expected a valid JSON writer instance");
30 writer->indent += JSON_INDENT_VALUE;
33 void mono_json_writer_indent_pop(JsonWriter* writer)
35 g_assert (writer && "Expected a valid JSON writer instance");
36 writer->indent -= JSON_INDENT_VALUE;
39 void mono_json_writer_indent(JsonWriter* writer)
41 g_assert (writer && "Expected a valid JSON writer instance");
43 int i = 0;
44 for (i = 0; i < writer->indent; ++i)
45 g_string_append_c (writer->text, ' ');
48 void mono_json_writer_vprintf(JsonWriter* writer, const gchar *format, va_list args)
50 g_assert (writer && "Expected a valid JSON writer instance");
51 g_string_append_vprintf (writer->text, format, args);
54 void mono_json_writer_printf(JsonWriter* writer, const gchar *format, ...)
56 g_assert (writer && "Expected a valid JSON writer instance");
58 va_list args;
59 va_start (args, format);
61 g_string_append_vprintf (writer->text, format, args);
63 va_end (args);
66 void mono_json_writer_array_begin(JsonWriter* writer)
68 g_assert (writer && "Expected a valid JSON writer instance");
69 g_string_append_printf (writer->text, "[\n");
70 writer->indent += JSON_INDENT_VALUE;
73 void mono_json_writer_array_end(JsonWriter* writer)
75 g_assert (writer && "Expected a valid JSON writer instance");
76 g_string_append_printf (writer->text, "]");
77 writer->indent -= JSON_INDENT_VALUE;
80 void mono_json_writer_object_begin(JsonWriter* writer)
82 g_assert (writer && "Expected a valid JSON writer instance");
83 mono_json_writer_printf (writer, "{\n");
84 writer->indent += JSON_INDENT_VALUE;
87 void mono_json_writer_object_end(JsonWriter* writer)
89 g_assert (writer && "Expected a valid JSON writer instance");
90 mono_json_writer_printf (writer, "}");
93 void mono_json_writer_object_key(JsonWriter* writer, const gchar* format, ...)
95 g_assert (writer && "Expected a valid JSON writer instance");
97 va_list args;
98 va_start (args, format);
100 g_string_append_printf (writer->text, "\"");
101 mono_json_writer_vprintf (writer, format, args);
102 g_string_append_printf (writer->text, "\" : ");
104 va_end (args);