Debian Codegraph @

gcc/ada/libgnat/a-wwboio.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . W I D E _ T E X T _ I O . W I D E _ B O U N D E D _ I O --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1997-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.Unchecked_Deallocation;
33
34 package body Ada.Wide_Text_IO.Wide_Bounded_IO is
35
36 type Wide_String_Access is access all Wide_String;
37
38 procedure Free (WSA : in out Wide_String_Access);
39 -- Perform an unchecked deallocation of a non-null string
40
41 ----------
42 -- Free --
43 ----------
44
45 procedure Free (WSA : in out Wide_String_Access) is
46 Null_Wide_String : constant Wide_String := "";
47
48 procedure Deallocate is
49 new Ada.Unchecked_Deallocation (Wide_String, Wide_String_Access);
50
51 begin
52 -- Do not try to free statically allocated null string
53
54 if WSA.all /= Null_Wide_String then
55 Deallocate (WSA);
56 end if;
57 end Free;
58
59 --------------
60 -- Get_Line --
61 --------------
62
63 function Get_Line return Wide_Bounded.Bounded_Wide_String is
64 begin
65 return Wide_Bounded.To_Bounded_Wide_String (Get_Line);
66 end Get_Line;
67
68 --------------
69 -- Get_Line --
70 --------------
71
72 function Get_Line
73 (File : File_Type) return Wide_Bounded.Bounded_Wide_String
74 is
75 begin
76 return Wide_Bounded.To_Bounded_Wide_String (Get_Line (File));
77 end Get_Line;
78
79 --------------
80 -- Get_Line --
81 --------------
82
83 procedure Get_Line
84 (Item : out Wide_Bounded.Bounded_Wide_String)
85 is
86 Buffer : Wide_String (1 .. 1000);
87 Last : Natural;
88 Str1 : Wide_String_Access;
89 Str2 : Wide_String_Access;
90
91 begin
92 Get_Line (Buffer, Last);
93 Str1 := new Wide_String'(Buffer (1 .. Last));
94
95 while Last = Buffer'Last loop
96 Get_Line (Buffer, Last);
97 Str2 := new Wide_String'(Str1.all & Buffer (1 .. Last));
98 Free (Str1);
99 Str1 := Str2;
100 end loop;
101
102 Item := Wide_Bounded.To_Bounded_Wide_String (Str1.all);
103 end Get_Line;
104
105 --------------
106 -- Get_Line --
107 --------------
108
109 procedure Get_Line
110 (File : File_Type;
111 Item : out Wide_Bounded.Bounded_Wide_String)
112 is
113 Buffer : Wide_String (1 .. 1000);
114 Last : Natural;
115 Str1 : Wide_String_Access;
116 Str2 : Wide_String_Access;
117
118 begin
119 Get_Line (File, Buffer, Last);
120 Str1 := new Wide_String'(Buffer (1 .. Last));
121
122 while Last = Buffer'Last loop
123 Get_Line (File, Buffer, Last);
124 Str2 := new Wide_String'(Str1.all & Buffer (1 .. Last));
125 Free (Str1);
126 Str1 := Str2;
127 end loop;
128
129 Item := Wide_Bounded.To_Bounded_Wide_String (Str1.all);
130 end Get_Line;
131
132 ---------
133 -- Put --
134 ---------
135
136 procedure Put
137 (Item : Wide_Bounded.Bounded_Wide_String)
138 is
139 begin
140 Put (Wide_Bounded.To_Wide_String (Item));
141 end Put;
142
143 ---------
144 -- Put --
145 ---------
146
147 procedure Put
148 (File : File_Type;
149 Item : Wide_Bounded.Bounded_Wide_String)
150 is
151 begin
152 Put (File, Wide_Bounded.To_Wide_String (Item));
153 end Put;
154
155 --------------
156 -- Put_Line --
157 --------------
158
159 procedure Put_Line
160 (Item : Wide_Bounded.Bounded_Wide_String)
161 is
162 begin
163 Put_Line (Wide_Bounded.To_Wide_String (Item));
164 end Put_Line;
165
166 --------------
167 -- Put_Line --
168 --------------
169
170 procedure Put_Line
171 (File : File_Type;
172 Item : Wide_Bounded.Bounded_Wide_String)
173 is
174 begin
175 Put_Line (File, Wide_Bounded.To_Wide_String (Item));
176 end Put_Line;
177
178 end Ada.Wide_Text_IO.Wide_Bounded_IO;