OSDN Git Service

2009-04-08 Thomas Quinot <quinot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-wtedit.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --             A D A . W I D E _ 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.Wide_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 Wide_String    := "$";
58    Default_Fill       : constant Wide_Character := ' ';
59    Default_Separator  : constant Wide_Character := ',';
60    Default_Radix_Mark : constant Wide_Character := '.';
61
62    generic
63       type Num is delta <> digits <>;
64       Default_Currency   : Wide_String :=
65                                 Wide_Text_IO.Editing.Default_Currency;
66       Default_Fill       : Wide_Character :=
67                                 Wide_Text_IO.Editing.Default_Fill;
68       Default_Separator  : Wide_Character :=
69                                 Wide_Text_IO.Editing.Default_Separator;
70       Default_Radix_Mark : Wide_Character :=
71                                 Wide_Text_IO.Editing.Default_Radix_Mark;
72
73    package Decimal_Output is
74
75       function Length
76         (Pic      : Picture;
77          Currency : Wide_String := Default_Currency) return Natural;
78
79       function Valid
80         (Item     : Num;
81          Pic      : Picture;
82          Currency : Wide_String := Default_Currency) return Boolean;
83
84       function Image
85         (Item       : Num;
86          Pic        : Picture;
87          Currency   : Wide_String    := Default_Currency;
88          Fill       : Wide_Character := Default_Fill;
89          Separator  : Wide_Character := Default_Separator;
90          Radix_Mark : Wide_Character := Default_Radix_Mark) return Wide_String;
91
92       procedure Put
93         (File       : File_Type;
94          Item       : Num;
95          Pic        : Picture;
96          Currency   : Wide_String    := Default_Currency;
97          Fill       : Wide_Character := Default_Fill;
98          Separator  : Wide_Character := Default_Separator;
99          Radix_Mark : Wide_Character := Default_Radix_Mark);
100
101       procedure Put
102         (Item       : Num;
103          Pic        : Picture;
104          Currency   : Wide_String    := Default_Currency;
105          Fill       : Wide_Character := Default_Fill;
106          Separator  : Wide_Character := Default_Separator;
107          Radix_Mark : Wide_Character := Default_Radix_Mark);
108
109       procedure Put
110         (To         : out Wide_String;
111          Item       : Num;
112          Pic        : Picture;
113          Currency   : Wide_String    := Default_Currency;
114          Fill       : Wide_Character := Default_Fill;
115          Separator  : Wide_Character := Default_Separator;
116          Radix_Mark : Wide_Character := Default_Radix_Mark);
117
118    end Decimal_Output;
119
120 private
121    MAX_PICSIZE      : constant := 50;
122    MAX_MONEYSIZE    : constant := 10;
123    Invalid_Position : constant := -1;
124
125    subtype Pic_Index is Natural range 0 .. MAX_PICSIZE;
126
127    type Picture_Record (Length : Pic_Index := 0) is record
128       Expanded : String (1 .. Length);
129    end record;
130
131    type Format_Record is record
132       Picture              : Picture_Record;
133       --  Read only
134
135       Blank_When_Zero      : Boolean;
136       --  Read/write
137
138       Original_BWZ         : Boolean;
139
140       --  The following components get written
141
142       Star_Fill            : Boolean := False;
143
144       Radix_Position       : Integer := Invalid_Position;
145
146       Sign_Position,
147       Second_Sign          : Integer := Invalid_Position;
148
149       Start_Float,
150       End_Float            : Integer := Invalid_Position;
151
152       Start_Currency,
153       End_Currency         : Integer := Invalid_Position;
154
155       Max_Leading_Digits   : Integer := 0;
156
157       Max_Trailing_Digits  : Integer := 0;
158
159       Max_Currency_Digits  : Integer := 0;
160
161       Floater              : Wide_Character := '!';
162       --  Initialized to illegal value
163
164    end record;
165
166    type Picture is record
167       Contents : Format_Record;
168    end record;
169
170    type Number_Attributes is record
171       Negative     : Boolean := False;
172
173       Has_Fraction : Boolean := False;
174
175       Start_Of_Int,
176       End_Of_Int,
177       Start_Of_Fraction,
178       End_Of_Fraction : Integer := Invalid_Position;    -- invalid value
179    end record;
180
181    function Parse_Number_String (Str : String) return Number_Attributes;
182    --  Assumed format is 'IMAGE or Fixed_IO.Put format (depends on no
183    --  trailing blanks...)
184
185    procedure Precalculate (Pic : in out Format_Record);
186    --  Precalculates fields from the user supplied data
187
188    function Format_Number
189      (Pic                 : Format_Record;
190       Number              : String;
191       Currency_Symbol     : Wide_String;
192       Fill_Character      : Wide_Character;
193       Separator_Character : Wide_Character;
194       Radix_Point         : Wide_Character) return Wide_String;
195    --  Formats number according to Pic
196
197    function Expand (Picture : String) return String;
198
199 end Ada.Wide_Text_IO.Editing;