OSDN Git Service

gcc/ada/
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-teioed.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --                  A D A . T E X T _ I O . E D I T I N G                   --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2006, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the  contents of the part following the private keyword. --
14 --                                                                          --
15 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
16 -- terms of the  GNU General Public License as published  by the Free Soft- --
17 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
18 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
21 -- for  more details.  You should have  received  a copy of the GNU General --
22 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
23 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
24 -- Boston, MA 02110-1301, USA.                                              --
25 --                                                                          --
26 -- As a special exception,  if other files  instantiate  generics from this --
27 -- unit, or you link  this unit with other files  to produce an executable, --
28 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
29 -- covered  by the  GNU  General  Public  License.  This exception does not --
30 -- however invalidate  any other reasons why  the executable file  might be --
31 -- covered by the  GNU Public License.                                      --
32 --                                                                          --
33 -- GNAT was originally developed  by the GNAT team at  New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
35 --                                                                          --
36 ------------------------------------------------------------------------------
37
38 package Ada.Text_IO.Editing is
39
40    type Picture is private;
41
42    function Valid
43      (Pic_String      : String;
44       Blank_When_Zero : Boolean := False) return Boolean;
45
46    function To_Picture
47      (Pic_String      : String;
48       Blank_When_Zero : Boolean := False) return Picture;
49
50    function Pic_String      (Pic : Picture) return String;
51    function Blank_When_Zero (Pic : Picture) return Boolean;
52
53    Max_Picture_Length : constant := 64;
54
55    Picture_Error : exception;
56
57    Default_Currency   : constant String    := "$";
58    Default_Fill       : constant Character := ' ';
59    Default_Separator  : constant Character := ',';
60    Default_Radix_Mark : constant Character := '.';
61
62    generic
63       type Num is delta <> digits <>;
64       Default_Currency   : String := Editing.Default_Currency;
65       Default_Fill       : Character := Editing.Default_Fill;
66       Default_Separator  : Character := Editing.Default_Separator;
67       Default_Radix_Mark : Character := Editing.Default_Radix_Mark;
68
69    package Decimal_Output is
70
71       function Length
72         (Pic      : Picture;
73          Currency : String := Default_Currency) return Natural;
74
75       function Valid
76         (Item     : Num;
77          Pic      : Picture;
78          Currency : String := Default_Currency) return Boolean;
79
80       function Image
81         (Item       : Num;
82          Pic        : Picture;
83          Currency   : String    := Default_Currency;
84          Fill       : Character := Default_Fill;
85          Separator  : Character := Default_Separator;
86          Radix_Mark : Character := Default_Radix_Mark) return String;
87
88       procedure Put
89         (File       : Ada.Text_IO.File_Type;
90          Item       : Num;
91          Pic        : Picture;
92          Currency   : String    := Default_Currency;
93          Fill       : Character := Default_Fill;
94          Separator  : Character := Default_Separator;
95          Radix_Mark : Character := Default_Radix_Mark);
96
97       procedure Put
98         (Item       : Num;
99          Pic        : Picture;
100          Currency   : String    := Default_Currency;
101          Fill       : Character := Default_Fill;
102          Separator  : Character := Default_Separator;
103          Radix_Mark : Character := Default_Radix_Mark);
104
105       procedure Put
106         (To         : out String;
107          Item       : Num;
108          Pic        : Picture;
109          Currency   : String    := Default_Currency;
110          Fill       : Character := Default_Fill;
111          Separator  : Character := Default_Separator;
112          Radix_Mark : Character := Default_Radix_Mark);
113
114    end Decimal_Output;
115
116 private
117
118    MAX_PICSIZE      : constant := 50;
119    MAX_MONEYSIZE    : constant := 10;
120    Invalid_Position : constant := -1;
121
122    subtype Pic_Index is Natural range 0 .. MAX_PICSIZE;
123
124    type Picture_Record (Length : Pic_Index := 0) is record
125       Expanded : String (1 .. Length);
126    end record;
127
128    type Format_Record is record
129       Picture              : Picture_Record;
130       --  Read only
131
132       Blank_When_Zero      : Boolean;
133       --  Read/write
134
135       Original_BWZ         : Boolean;
136
137       --  The following components get written
138
139       Star_Fill            : Boolean := False;
140
141       Radix_Position       : Integer := Invalid_Position;
142
143       Sign_Position,
144       Second_Sign          : Integer := Invalid_Position;
145
146       Start_Float,
147       End_Float            : Integer := Invalid_Position;
148
149       Start_Currency,
150       End_Currency         : Integer := Invalid_Position;
151
152       Max_Leading_Digits   : Integer := 0;
153
154       Max_Trailing_Digits  : Integer := 0;
155
156       Max_Currency_Digits  : Integer := 0;
157
158       Floater              : Character := '!';
159       --  Initialized to illegal value
160
161    end record;
162
163    type Picture is record
164       Contents : Format_Record;
165    end record;
166
167    type Number_Attributes is record
168       Negative     : Boolean := False;
169
170       Has_Fraction : Boolean := False;
171
172       Start_Of_Int,
173       End_Of_Int,
174       Start_Of_Fraction,
175       End_Of_Fraction : Integer := Invalid_Position;    -- invalid value
176    end record;
177
178    function Parse_Number_String (Str : String) return Number_Attributes;
179    --  Assumed format is 'IMAGE or Fixed_IO.Put format (depends on no
180    --  trailing blanks...)
181
182    procedure Precalculate (Pic : in out Format_Record);
183    --  Precalculates fields from the user supplied data
184
185    function Format_Number
186      (Pic                 : Format_Record;
187       Number              : String;
188       Currency_Symbol     : String;
189       Fill_Character      : Character;
190       Separator_Character : Character;
191       Radix_Point         : Character) return String;
192    --  Formats number according to Pic
193
194    function Expand (Picture : String) return String;
195
196 end Ada.Text_IO.Editing;