blob: 072cab4a4928cca595d20c6ef248bf038903222b (
plain)
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
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- D I A G N O S T I C S . J S O N _ U T I L S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Output; use Output;
package body Diagnostics.JSON_Utils is
-----------------
-- Begin_Block --
-----------------
procedure Begin_Block is
begin
Indent_Level := Indent_Level + 1;
end Begin_Block;
---------------
-- End_Block --
---------------
procedure End_Block is
begin
Indent_Level := Indent_Level - 1;
end End_Block;
procedure Indent is begin
if JSON_FORMATTING then
for I in 1 .. INDENT_SIZE * Indent_Level loop
Write_Char (' ');
end loop;
end if;
end Indent;
-------------------
-- NL_And_Indent --
-------------------
procedure NL_And_Indent is
begin
if JSON_FORMATTING then
Write_Eol;
Indent;
end if;
end NL_And_Indent;
-----------------------------
-- Write_Boolean_Attribute --
-----------------------------
procedure Write_Boolean_Attribute (Name : String; Value : Boolean) is
begin
Write_Str ("""" & Name & """" & ": ");
Write_Str (if Value then "true" else "false");
end Write_Boolean_Attribute;
-------------------------
-- Write_Int_Attribute --
-------------------------
procedure Write_Int_Attribute (Name : String; Value : Int) is
begin
Write_Str ("""" & Name & """" & ": ");
Write_Int (Value);
end Write_Int_Attribute;
-------------------------------
-- Write_JSON_Escaped_String --
-------------------------------
procedure Write_JSON_Escaped_String (Str : String) is
begin
for C of Str loop
if C = '"' or else C = '\' then
Write_Char ('\');
end if;
Write_Char (C);
end loop;
end Write_JSON_Escaped_String;
----------------------------
-- Write_String_Attribute --
----------------------------
procedure Write_String_Attribute (Name : String; Value : String) is
begin
Write_Str ("""" & Name & """" & ": ");
Write_Char ('"');
Write_JSON_Escaped_String (Value);
Write_Char ('"');
end Write_String_Attribute;
end Diagnostics.JSON_Utils;
|