Debian Codegraph @

gcc/ada/libgnat/a-sttebu.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- ADA.STRINGS.TEXT_BUFFERS --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2020-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. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 with Ada.Strings.UTF_Encoding.Strings;
33 with Ada.Strings.UTF_Encoding.Wide_Strings;
34 with Ada.Strings.UTF_Encoding.Wide_Wide_Strings;
35
36 package body Ada.Strings.Text_Buffers is
37 function Current_Indent
38 (Buffer : Root_Buffer_Type) return Text_Buffer_Count is
39 (Text_Buffer_Count (Buffer.Indentation));
40
41 procedure Increase_Indent
42 (Buffer : in out Root_Buffer_Type;
43 Amount : Text_Buffer_Count := Standard_Indent)
44 is
45 begin
46 Buffer.Indentation := @ + Natural (Amount);
47 end Increase_Indent;
48
49 procedure Decrease_Indent
50 (Buffer : in out Root_Buffer_Type;
51 Amount : Text_Buffer_Count := Standard_Indent)
52 is
53 begin
54 Buffer.Indentation := @ - Natural (Amount);
55 end Decrease_Indent;
56
57 procedure Set_Trim_Leading_Spaces
58 (Buffer : in out Root_Buffer_Type;
59 Trim : Boolean := True) is
60 begin
61 Buffer.Trim_Leading_White_Spaces := Trim;
62 end Set_Trim_Leading_Spaces;
63
64 function Trim_Leading_Spaces
65 (Buffer : Root_Buffer_Type) return Boolean is
66 begin
67 return Buffer.Trim_Leading_White_Spaces;
68 end Trim_Leading_Spaces;
69
70 package body Output_Mapping is
71 -- Implement indentation in Put_UTF_8 and New_Line.
72 -- Implement other output procedures using Put_UTF_8.
73
74 procedure Put (Buffer : in out Buffer_Type; Item : String) is
75 begin
76 Put_UTF_8 (Buffer, UTF_Encoding.Strings.Encode (Item));
77 end Put;
78
79 procedure Wide_Put (Buffer : in out Buffer_Type; Item : Wide_String) is
80 begin
81 Buffer.All_8_Bits :=
82 @ and then
83 (for all WChar of Item => Wide_Character'Pos (WChar) < 256);
84
85 Put_UTF_8 (Buffer, UTF_Encoding.Wide_Strings.Encode (Item));
86 end Wide_Put;
87
88 procedure Wide_Wide_Put
89 (Buffer : in out Buffer_Type; Item : Wide_Wide_String)
90 is
91 begin
92 Buffer.All_8_Bits :=
93 @ and then
94 (for all WWChar of Item => Wide_Wide_Character'Pos (WWChar) < 256);
95
96 Put_UTF_8 (Buffer, UTF_Encoding.Wide_Wide_Strings.Encode (Item));
97 end Wide_Wide_Put;
98
99 procedure Put_UTF_8
100 (Buffer : in out Buffer_Type;
101 Item : UTF_Encoding.UTF_8_String) is
102 begin
103 if Item'Length = 0 then
104 return;
105 end if;
106
107 if Buffer.Indent_Pending
108 and then not Buffer.Trim_Leading_White_Spaces
109 then
110 Buffer.Indent_Pending := False;
111 if Buffer.Indentation > 0 then
112 Put_UTF_8_Implementation
113 (Buffer, [1 .. Buffer.Indentation => ' ']);
114 end if;
115 end if;
116
117 Put_UTF_8_Implementation (Buffer, Item);
118 end Put_UTF_8;
119
120 procedure Wide_Put_UTF_16
121 (Buffer : in out Buffer_Type; Item : UTF_Encoding.UTF_16_Wide_String)
122 is
123 begin
124 Wide_Wide_Put (Buffer, UTF_Encoding.Wide_Wide_Strings.Decode (Item));
125 end Wide_Put_UTF_16;
126
127 procedure New_Line (Buffer : in out Buffer_Type) is
128 begin
129 Buffer.Indent_Pending := False; -- just for a moment
130 Put (Buffer, [ASCII.LF]);
131 Buffer.Indent_Pending := True;
132 Buffer.UTF_8_Column := 1;
133 Buffer.Trim_Leading_White_Spaces := False;
134 end New_Line;
135
136 end Output_Mapping;
137
138 end Ada.Strings.Text_Buffers;