1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . T E X T _ I O . D E C I M A L _ 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
.Decimal_Aux
is
43 Scale
: Integer) return Int
45 Buf
: String (1 .. Field
'Last);
46 Ptr
: aliased Integer;
52 Load_Width
(File
, Width
, Buf
, Stop
);
53 String_Skip
(Buf
, Ptr
);
55 Load_Real
(File
, Buf
, Stop
);
59 Item
:= Scan
(Buf
, Ptr
'Access, Stop
, Scale
);
60 Check_End_Of_Field
(Buf
, Stop
, Ptr
, Width
);
71 Scale
: Integer) return Int
73 Pos
: aliased Integer;
77 String_Skip
(From
, Pos
);
78 Item
:= Scan
(From
, Pos
'Access, From
'Last, Scale
);
83 when Constraint_Error
=>
100 Buf
: String (1 .. Field
'Last);
104 Set_Image
(Item
, Buf
, Ptr
, Scale
, Fore
, Aft
, Exp
);
105 Put_Item
(File
, Buf
(1 .. Ptr
));
119 Buf
: String (1 .. Positive'Max (Field
'Last, To
'Length));
124 -- Compute Fore, allowing for the decimal dot and Aft digits
126 Fore
:= To
'Length - 1 - Field
'Max (1, Aft
);
128 -- Allow for Exp and one more for E if exponent present
131 Fore
:= Fore
- 1 - Field
'Max (2, Exp
);
134 -- Make sure we have enough room
136 if Fore
< 1 + Boolean'Pos (Item
< 0) then
140 -- Do the conversion and check length of result
142 Set_Image
(Item
, Buf
, Ptr
, Scale
, Fore
, Aft
, Exp
);
144 if Ptr
> To
'Length then
147 To
:= Buf
(1 .. Ptr
);
151 end Ada
.Text_IO
.Decimal_Aux
;