1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT RUN-TIME COMPONENTS                         --
4--                                                                          --
5--        A D A . W I D E _ 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-2018, 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 3,  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.                                     --
21--                                                                          --
22-- As a special exception under Section 7 of GPL version 3, you are granted --
23-- additional permissions described in the GCC Runtime Library Exception,   --
24-- version 3.1, as published by the Free Software Foundation.               --
25--                                                                          --
26-- You should have received a copy of the GNU General Public License and    --
27-- a copy of the GCC Runtime Library Exception along with this program;     --
28-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
29-- <http://www.gnu.org/licenses/>.                                          --
30--                                                                          --
31-- GNAT was originally developed  by the GNAT team at  New York University. --
32-- Extensive contributions were provided by Ada Core Technologies Inc.      --
33--                                                                          --
34------------------------------------------------------------------------------
35
36package Ada.Wide_Wide_Text_IO.Editing is
37
38   type Picture is private;
39
40   function Valid
41     (Pic_String      : String;
42      Blank_When_Zero : Boolean := False) return Boolean;
43
44   function To_Picture
45     (Pic_String      : String;
46      Blank_When_Zero : Boolean := False) return Picture;
47
48   function Pic_String      (Pic : Picture) return String;
49   function Blank_When_Zero (Pic : Picture) return Boolean;
50
51   Max_Picture_Length : constant := 64;
52
53   Picture_Error : exception;
54
55   Default_Currency   : constant Wide_Wide_String    := "$";
56   Default_Fill       : constant Wide_Wide_Character := ' ';
57   Default_Separator  : constant Wide_Wide_Character := ',';
58   Default_Radix_Mark : constant Wide_Wide_Character := '.';
59
60   generic
61      type Num is delta <> digits <>;
62      Default_Currency   : Wide_Wide_String :=
63                                Wide_Wide_Text_IO.Editing.Default_Currency;
64      Default_Fill       : Wide_Wide_Character :=
65                                Wide_Wide_Text_IO.Editing.Default_Fill;
66      Default_Separator  : Wide_Wide_Character :=
67                                Wide_Wide_Text_IO.Editing.Default_Separator;
68      Default_Radix_Mark : Wide_Wide_Character :=
69                                Wide_Wide_Text_IO.Editing.Default_Radix_Mark;
70
71   package Decimal_Output is
72
73      function Length
74        (Pic      : Picture;
75         Currency : Wide_Wide_String := Default_Currency) return Natural;
76
77      function Valid
78        (Item     : Num;
79         Pic      : Picture;
80         Currency : Wide_Wide_String := Default_Currency) return Boolean;
81
82      function Image
83        (Item       : Num;
84         Pic        : Picture;
85         Currency   : Wide_Wide_String    := Default_Currency;
86         Fill       : Wide_Wide_Character := Default_Fill;
87         Separator  : Wide_Wide_Character := Default_Separator;
88         Radix_Mark : Wide_Wide_Character := Default_Radix_Mark)
89         return Wide_Wide_String;
90
91      procedure Put
92        (File       : File_Type;
93         Item       : Num;
94         Pic        : Picture;
95         Currency   : Wide_Wide_String    := Default_Currency;
96         Fill       : Wide_Wide_Character := Default_Fill;
97         Separator  : Wide_Wide_Character := Default_Separator;
98         Radix_Mark : Wide_Wide_Character := Default_Radix_Mark);
99
100      procedure Put
101        (Item       : Num;
102         Pic        : Picture;
103         Currency   : Wide_Wide_String    := Default_Currency;
104         Fill       : Wide_Wide_Character := Default_Fill;
105         Separator  : Wide_Wide_Character := Default_Separator;
106         Radix_Mark : Wide_Wide_Character := Default_Radix_Mark);
107
108      procedure Put
109        (To         : out Wide_Wide_String;
110         Item       : Num;
111         Pic        : Picture;
112         Currency   : Wide_Wide_String    := Default_Currency;
113         Fill       : Wide_Wide_Character := Default_Fill;
114         Separator  : Wide_Wide_Character := Default_Separator;
115         Radix_Mark : Wide_Wide_Character := Default_Radix_Mark);
116
117   end Decimal_Output;
118
119private
120   MAX_PICSIZE      : constant := 50;
121   MAX_MONEYSIZE    : constant := 10;
122   Invalid_Position : constant := -1;
123
124   subtype Pic_Index is Natural range 0 .. MAX_PICSIZE;
125
126   type Picture_Record (Length : Pic_Index := 0) is record
127      Expanded : String (1 .. Length);
128   end record;
129
130   type Format_Record is record
131      Picture              : Picture_Record;
132      --  Read only
133
134      Blank_When_Zero      : Boolean;
135      --  Read/write
136
137      Original_BWZ         : Boolean;
138
139      --  The following components get written
140
141      Star_Fill            : Boolean := False;
142
143      Radix_Position       : Integer := Invalid_Position;
144
145      Sign_Position,
146      Second_Sign          : Integer := Invalid_Position;
147
148      Start_Float,
149      End_Float            : Integer := Invalid_Position;
150
151      Start_Currency,
152      End_Currency         : Integer := Invalid_Position;
153
154      Max_Leading_Digits   : Integer := 0;
155
156      Max_Trailing_Digits  : Integer := 0;
157
158      Max_Currency_Digits  : Integer := 0;
159
160      Floater              : Wide_Wide_Character := '!';
161      --  Initialized to illegal value
162
163   end record;
164
165   type Picture is record
166      Contents : Format_Record;
167   end record;
168
169   type Number_Attributes is record
170      Negative     : Boolean := False;
171
172      Has_Fraction : Boolean := False;
173
174      Start_Of_Int,
175      End_Of_Int,
176      Start_Of_Fraction,
177      End_Of_Fraction : Integer := Invalid_Position;    -- invalid value
178   end record;
179
180   function Parse_Number_String (Str : String) return Number_Attributes;
181   --  Assumed format is 'IMAGE or Fixed_IO.Put format (depends on no
182   --  trailing blanks...)
183
184   procedure Precalculate (Pic : in out Format_Record);
185   --  Precalculates fields from the user supplied data
186
187   function Format_Number
188     (Pic                 : Format_Record;
189      Number              : String;
190      Currency_Symbol     : Wide_Wide_String;
191      Fill_Character      : Wide_Wide_Character;
192      Separator_Character : Wide_Wide_Character;
193      Radix_Point         : Wide_Wide_Character) return Wide_Wide_String;
194   --  Formats number according to Pic
195
196   function Expand (Picture : String) return String;
197
198end Ada.Wide_Wide_Text_IO.Editing;
199