| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- D I A G N O S T I C S . J S O N _ U T I L S -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| 17 |
-- for more details. You should have received a copy of the GNU General -- |
| 18 |
-- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| 19 |
-- http://www.gnu.org/licenses for a complete copy of the license. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
with Output; use Output; |
| 26 |
|
| 27 |
package body Diagnostics.JSON_Utils is |
| 28 |
|
| 29 |
----------------- |
| 30 |
-- Begin_Block -- |
| 31 |
----------------- |
| 32 |
|
| 33 |
procedure Begin_Block is |
| 34 |
begin |
| 35 |
Indent_Level := Indent_Level + 1; |
| 36 |
end Begin_Block; |
| 37 |
|
| 38 |
--------------- |
| 39 |
-- End_Block -- |
| 40 |
--------------- |
| 41 |
|
| 42 |
procedure End_Block is |
| 43 |
begin |
| 44 |
Indent_Level := Indent_Level - 1; |
| 45 |
end End_Block; |
| 46 |
|
| 47 |
procedure Indent is begin |
| 48 |
if JSON_FORMATTING then |
| 49 |
for I in 1 .. INDENT_SIZE * Indent_Level loop |
| 50 |
Write_Char (' '); |
| 51 |
end loop; |
| 52 |
end if; |
| 53 |
end Indent; |
| 54 |
|
| 55 |
------------------- |
| 56 |
-- NL_And_Indent -- |
| 57 |
------------------- |
| 58 |
|
| 59 |
procedure NL_And_Indent is |
| 60 |
begin |
| 61 |
if JSON_FORMATTING then |
| 62 |
Write_Eol; |
| 63 |
Indent; |
| 64 |
end if; |
| 65 |
end NL_And_Indent; |
| 66 |
|
| 67 |
----------------------------- |
| 68 |
-- Write_Boolean_Attribute -- |
| 69 |
----------------------------- |
| 70 |
|
| 71 |
procedure Write_Boolean_Attribute (Name : String; Value : Boolean) is |
| 72 |
|
| 73 |
begin |
| 74 |
Write_Str ("""" & Name & """" & ": "); |
| 75 |
Write_Str (if Value then "true" else "false"); |
| 76 |
end Write_Boolean_Attribute; |
| 77 |
|
| 78 |
------------------------- |
| 79 |
-- Write_Int_Attribute -- |
| 80 |
------------------------- |
| 81 |
|
| 82 |
procedure Write_Int_Attribute (Name : String; Value : Int) is |
| 83 |
begin |
| 84 |
Write_Str ("""" & Name & """" & ": "); |
| 85 |
Write_Int (Value); |
| 86 |
end Write_Int_Attribute; |
| 87 |
|
| 88 |
------------------------------- |
| 89 |
-- Write_JSON_Escaped_String -- |
| 90 |
------------------------------- |
| 91 |
|
| 92 |
procedure Write_JSON_Escaped_String (Str : String) is |
| 93 |
begin |
| 94 |
for C of Str loop |
| 95 |
if C = '"' or else C = '\' then |
| 96 |
Write_Char ('\'); |
| 97 |
end if; |
| 98 |
|
| 99 |
Write_Char (C); |
| 100 |
end loop; |
| 101 |
end Write_JSON_Escaped_String; |
| 102 |
|
| 103 |
---------------------------- |
| 104 |
-- Write_String_Attribute -- |
| 105 |
---------------------------- |
| 106 |
|
| 107 |
procedure Write_String_Attribute (Name : String; Value : String) is |
| 108 |
begin |
| 109 |
Write_Str ("""" & Name & """" & ": "); |
| 110 |
Write_Char ('"'); |
| 111 |
Write_JSON_Escaped_String (Value); |
| 112 |
Write_Char ('"'); |
| 113 |
end Write_String_Attribute; |
| 114 |
|
| 115 |
end Diagnostics.JSON_Utils; |