a-teioed.ads 7.37 KB
Newer Older
Richard Kenner committed
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                         GNAT RUN-TIME COMPONENTS                         --
--                                                                          --
--                  A D A . T E X T _ I O . E D I T I N G                   --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
9
--          Copyright (C) 1992-2006, Free Software Foundation, Inc.         --
Richard Kenner committed
10 11 12 13 14 15 16 17 18 19 20 21 22
--                                                                          --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
-- apply solely to the  contents of the part following the private keyword. --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License  distributed with GNAT;  see file COPYING.  If not, write --
R. Kelley Cook committed
23 24
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
-- Boston, MA 02110-1301, USA.                                              --
Richard Kenner committed
25 26 27 28 29 30 31 32 33
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable  to  be --
-- covered  by the  GNU  General  Public  License.  This exception does not --
-- however invalidate  any other reasons why  the executable file  might be --
-- covered by the  GNU Public License.                                      --
--                                                                          --
-- GNAT was originally developed  by the GNAT team at  New York University. --
34
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
Richard Kenner committed
35 36 37 38 39 40 41 42
--                                                                          --
------------------------------------------------------------------------------

package Ada.Text_IO.Editing is

   type Picture is private;

   function Valid
43 44
     (Pic_String      : String;
      Blank_When_Zero : Boolean := False) return Boolean;
Richard Kenner committed
45 46

   function To_Picture
47 48
     (Pic_String      : String;
      Blank_When_Zero : Boolean := False) return Picture;
Richard Kenner committed
49

50 51
   function Pic_String      (Pic : Picture) return String;
   function Blank_When_Zero (Pic : Picture) return Boolean;
Richard Kenner committed
52 53 54 55 56 57 58 59 60 61 62 63

   Max_Picture_Length : constant := 64;

   Picture_Error : exception;

   Default_Currency   : constant String    := "$";
   Default_Fill       : constant Character := ' ';
   Default_Separator  : constant Character := ',';
   Default_Radix_Mark : constant Character := '.';

   generic
      type Num is delta <> digits <>;
64 65 66 67
      Default_Currency   : String := Editing.Default_Currency;
      Default_Fill       : Character := Editing.Default_Fill;
      Default_Separator  : Character := Editing.Default_Separator;
      Default_Radix_Mark : Character := Editing.Default_Radix_Mark;
Richard Kenner committed
68 69 70 71

   package Decimal_Output is

      function Length
72 73
        (Pic      : Picture;
         Currency : String := Default_Currency) return Natural;
Richard Kenner committed
74 75 76

      function Valid
        (Item     : Num;
77 78
         Pic      : Picture;
         Currency : String := Default_Currency) return Boolean;
Richard Kenner committed
79 80 81

      function Image
        (Item       : Num;
82 83 84 85 86
         Pic        : Picture;
         Currency   : String    := Default_Currency;
         Fill       : Character := Default_Fill;
         Separator  : Character := Default_Separator;
         Radix_Mark : Character := Default_Radix_Mark) return String;
Richard Kenner committed
87 88

      procedure Put
89
        (File       : Ada.Text_IO.File_Type;
Richard Kenner committed
90
         Item       : Num;
91 92 93 94 95
         Pic        : Picture;
         Currency   : String    := Default_Currency;
         Fill       : Character := Default_Fill;
         Separator  : Character := Default_Separator;
         Radix_Mark : Character := Default_Radix_Mark);
Richard Kenner committed
96 97 98

      procedure Put
        (Item       : Num;
99 100 101 102 103
         Pic        : Picture;
         Currency   : String    := Default_Currency;
         Fill       : Character := Default_Fill;
         Separator  : Character := Default_Separator;
         Radix_Mark : Character := Default_Radix_Mark);
Richard Kenner committed
104 105 106 107

      procedure Put
        (To         : out String;
         Item       : Num;
108 109 110 111 112
         Pic        : Picture;
         Currency   : String    := Default_Currency;
         Fill       : Character := Default_Fill;
         Separator  : Character := Default_Separator;
         Radix_Mark : Character := Default_Radix_Mark);
Richard Kenner committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190

   end Decimal_Output;

private

   MAX_PICSIZE      : constant := 50;
   MAX_MONEYSIZE    : constant := 10;
   Invalid_Position : constant := -1;

   subtype Pic_Index is Natural range 0 .. MAX_PICSIZE;

   type Picture_Record (Length : Pic_Index := 0) is record
      Expanded : String (1 .. Length);
   end record;

   type Format_Record is record
      Picture              : Picture_Record;
      --  Read only

      Blank_When_Zero      : Boolean;
      --  Read/write

      Original_BWZ         : Boolean;

      --  The following components get written

      Star_Fill            : Boolean := False;

      Radix_Position       : Integer := Invalid_Position;

      Sign_Position,
      Second_Sign          : Integer := Invalid_Position;

      Start_Float,
      End_Float            : Integer := Invalid_Position;

      Start_Currency,
      End_Currency         : Integer := Invalid_Position;

      Max_Leading_Digits   : Integer := 0;

      Max_Trailing_Digits  : Integer := 0;

      Max_Currency_Digits  : Integer := 0;

      Floater              : Character := '!';
      --  Initialized to illegal value

   end record;

   type Picture is record
      Contents : Format_Record;
   end record;

   type Number_Attributes is record
      Negative     : Boolean := False;

      Has_Fraction : Boolean := False;

      Start_Of_Int,
      End_Of_Int,
      Start_Of_Fraction,
      End_Of_Fraction : Integer := Invalid_Position;    -- invalid value
   end record;

   function Parse_Number_String (Str : String) return Number_Attributes;
   --  Assumed format is 'IMAGE or Fixed_IO.Put format (depends on no
   --  trailing blanks...)

   procedure Precalculate (Pic : in out Format_Record);
   --  Precalculates fields from the user supplied data

   function Format_Number
     (Pic                 : Format_Record;
      Number              : String;
      Currency_Symbol     : String;
      Fill_Character      : Character;
      Separator_Character : Character;
191
      Radix_Point         : Character) return String;
Richard Kenner committed
192 193
   --  Formats number according to Pic

194
   function Expand (Picture : String) return String;
Richard Kenner committed
195 196

end Ada.Text_IO.Editing;