1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . T E X T _ I O . C O M P L E X _ A U X --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Ada
.Text_IO
.Generic_Aux
; use Ada
.Text_IO
.Generic_Aux
;
34 package body Ada
.Text_IO
.Complex_Aux
is
46 Buf
: String (1 .. Field
'Last);
48 Ptr
: aliased Integer;
49 Paren
: Boolean := False;
52 -- General note for following code, exceptions from the calls to
53 -- Get for components of the complex value are propagated.
56 Load_Width
(File
, Width
, Buf
, Stop
);
57 Gets
(Buf
(1 .. Stop
), ItemR
, ItemI
, Ptr
);
59 for J
in Ptr
+ 1 .. Stop
loop
60 if not Is_Blank
(Buf
(J
)) then
70 Load
(File
, Buf
, Ptr
, '(', Paren
);
71 Aux
.Get
(File
, ItemR
, 0);
73 Load
(File
, Buf
, Ptr
, ',');
74 Aux
.Get
(File
, ItemI
, 0);
78 Load
(File
, Buf
, Ptr
, ')', Paren
);
101 String_Skip
(From
, Pos
);
103 if From
(Pos
) = '(' then
110 Aux
.Gets
(From
(Pos
.. From
'Last), ItemR
, Pos
);
112 String_Skip
(From
(Pos
+ 1 .. From
'Last), Pos
);
114 if From
(Pos
) = ',' then
118 Aux
.Gets
(From
(Pos
.. From
'Last), ItemI
, Pos
);
121 String_Skip
(From
(Pos
+ 1 .. From
'Last), Pos
);
123 if From
(Pos
) /= ')' then
145 Aux
.Put
(File
, ItemR
, Fore
, Aft
, Exp
);
147 Aux
.Put
(File
, ItemI
, Fore
, Aft
, Exp
);
162 I_String
: String (1 .. 3 * Field
'Last);
163 R_String
: String (1 .. 3 * Field
'Last);
169 -- Both parts are initially converted with a Fore of 0
172 Aux
.Set_Image
(ItemR
, R_String
, Rptr
, 0, Aft
, Exp
);
174 Aux
.Set_Image
(ItemI
, I_String
, Iptr
, 0, Aft
, Exp
);
176 -- Check room for both parts plus parens plus comma (RM G.1.3(34))
178 if Rptr
+ Iptr
+ 3 > To
'Length then
182 -- If there is room, layout result according to (RM G.1.3(31-33))
184 To
(To
'First) := '(';
185 To
(To
'First + 1 .. To
'First + Rptr
) := R_String
(1 .. Rptr
);
186 To
(To
'First + Rptr
+ 1) := ',';
189 To
(To
'Last - Iptr
.. To
'Last - 1) := I_String
(1 .. Iptr
);
191 for J
in To
'First + Rptr
+ 2 .. To
'Last - Iptr
- 1 loop
197 end Ada
.Text_IO
.Complex_Aux
;