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