1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- A D A . T E X T _ I O . E D I T I N G --
9 -- Copyright (C) 1992-2001 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 with Ada
.Strings
.Fixed
;
35 package body Ada
.Text_IO
.Editing
is
37 package Strings
renames Ada
.Strings
;
38 package Strings_Fixed
renames Ada
.Strings
.Fixed
;
39 package Text_IO
renames Ada
.Text_IO
;
45 function Blank_When_Zero
(Pic
: in Picture
) return Boolean is
47 return Pic
.Contents
.Original_BWZ
;
54 function Expand
(Picture
: in String) return String is
55 Result
: String (1 .. MAX_PICSIZE
);
56 Picture_Index
: Integer := Picture
'First;
57 Result_Index
: Integer := Result
'First;
61 package Int_IO
is new Ada
.Text_IO
.Integer_IO
(Integer);
64 if Picture
'Length < 1 then
68 if Picture
(Picture
'First) = '(' then
73 case Picture
(Picture_Index
) is
76 Int_IO
.Get
(Picture
(Picture_Index
+ 1 .. Picture
'Last),
79 if Picture
(Last
+ 1) /= ')' then
83 -- In what follows note that one copy of the repeated
84 -- character has already been made, so a count of one is a
85 -- no-op, and a count of zero erases a character.
87 for J
in 2 .. Count
loop
88 Result
(Result_Index
+ J
- 2) := Picture
(Picture_Index
- 1);
91 Result_Index
:= Result_Index
+ Count
- 1;
93 -- Last + 1 was a ')' throw it away too.
95 Picture_Index
:= Last
+ 2;
101 Result
(Result_Index
) := Picture
(Picture_Index
);
102 Picture_Index
:= Picture_Index
+ 1;
103 Result_Index
:= Result_Index
+ 1;
107 exit when Picture_Index
> Picture
'Last;
110 return Result
(1 .. Result_Index
- 1);
122 function Format_Number
123 (Pic
: Format_Record
;
125 Currency_Symbol
: String;
126 Fill_Character
: Character;
127 Separator_Character
: Character;
128 Radix_Point
: Character)
131 Attrs
: Number_Attributes
:= Parse_Number_String
(Number
);
133 Rounded
: String := Number
;
135 Sign_Position
: Integer := Pic
.Sign_Position
; -- may float.
137 Answer
: String (1 .. Pic
.Picture
.Length
) := Pic
.Picture
.Expanded
;
139 Currency_Pos
: Integer := Pic
.Start_Currency
;
141 Dollar
: Boolean := False;
142 -- Overridden immediately if necessary.
144 Zero
: Boolean := True;
145 -- Set to False when a non-zero digit is output.
149 -- If the picture has fewer decimal places than the number, the image
150 -- must be rounded according to the usual rules.
152 if Attrs
.Has_Fraction
then
154 R
: constant Integer :=
155 (Attrs
.End_Of_Fraction
- Attrs
.Start_Of_Fraction
+ 1)
156 - Pic
.Max_Trailing_Digits
;
161 R_Pos
:= Attrs
.End_Of_Fraction
- R
;
163 if Rounded
(R_Pos
+ 1) > '4' then
165 if Rounded
(R_Pos
) = '.' then
169 if Rounded
(R_Pos
) /= '9' then
170 Rounded
(R_Pos
) := Character'Succ (Rounded
(R_Pos
));
172 Rounded
(R_Pos
) := '0';
176 if Rounded
(R_Pos
) = '.' then
180 if Rounded
(R_Pos
) /= '9' then
181 Rounded
(R_Pos
) := Character'Succ (Rounded
(R_Pos
));
184 Rounded
(R_Pos
) := '0';
189 -- The rounding may add a digit in front. Either the
190 -- leading blank or the sign (already captured) can
194 Rounded
(R_Pos
) := '1';
195 Attrs
.Start_Of_Int
:= Attrs
.Start_Of_Int
- 1;
203 if Pic
.Start_Currency
/= Invalid_Position
then
204 Dollar
:= Answer
(Pic
.Start_Currency
) = '$';
207 -- Fix up "direct inserts" outside the playing field. Set up as one
208 -- loop to do the beginning, one (reverse) loop to do the end.
212 exit when Last
= Pic
.Start_Float
;
213 exit when Last
= Pic
.Radix_Position
;
214 exit when Answer
(Last
) = '9';
216 case Answer
(Last
) is
219 Answer
(Last
) := Separator_Character
;
222 Answer
(Last
) := ' ';
229 exit when Last
= Answer
'Last;
234 -- Now for the end...
236 for J
in reverse Last
.. Answer
'Last loop
237 exit when J
= Pic
.Radix_Position
;
239 -- Do this test First, Separator_Character can equal Pic.Floater.
241 if Answer
(J
) = Pic
.Floater
then
248 Answer
(J
) := Separator_Character
;
264 if Pic
.Start_Currency
/= -1
265 and then Answer
(Pic
.Start_Currency
) = '#'
266 and then Pic
.Floater
/= '#'
268 if Currency_Symbol
'Length >
269 Pic
.End_Currency
- Pic
.Start_Currency
+ 1
273 elsif Currency_Symbol
'Length =
274 Pic
.End_Currency
- Pic
.Start_Currency
+ 1
276 Answer
(Pic
.Start_Currency
.. Pic
.End_Currency
) :=
279 elsif Pic
.Radix_Position
= Invalid_Position
280 or else Pic
.Start_Currency
< Pic
.Radix_Position
282 Answer
(Pic
.Start_Currency
.. Pic
.End_Currency
) :=
284 Answer
(Pic
.End_Currency
- Currency_Symbol
'Length + 1 ..
285 Pic
.End_Currency
) := Currency_Symbol
;
288 Answer
(Pic
.Start_Currency
.. Pic
.End_Currency
) :=
290 Answer
(Pic
.Start_Currency
..
291 Pic
.Start_Currency
+ Currency_Symbol
'Length - 1) :=
296 -- Fill in leading digits
298 if Attrs
.End_Of_Int
- Attrs
.Start_Of_Int
+ 1 >
299 Pic
.Max_Leading_Digits
304 if Pic
.Radix_Position
= Invalid_Position
then
305 Position
:= Answer
'Last;
307 Position
:= Pic
.Radix_Position
- 1;
310 for J
in reverse Attrs
.Start_Of_Int
.. Attrs
.End_Of_Int
loop
312 while Answer
(Position
) /= '9'
313 and Answer
(Position
) /= Pic
.Floater
315 if Answer
(Position
) = '_' then
316 Answer
(Position
) := Separator_Character
;
318 elsif Answer
(Position
) = 'b' then
319 Answer
(Position
) := ' ';
322 Position
:= Position
- 1;
325 Answer
(Position
) := Rounded
(J
);
327 if Rounded
(J
) /= '0' then
331 Position
:= Position
- 1;
336 if Pic
.Start_Float
= Invalid_Position
then
338 -- No leading floats, but need to change '9' to '0', '_' to
339 -- Separator_Character and 'b' to ' '.
341 for J
in Last
.. Position
loop
343 -- Last set when fixing the "uninteresting" leaders above.
344 -- Don't duplicate the work.
346 if Answer
(J
) = '9' then
349 elsif Answer
(J
) = '_' then
350 Answer
(J
) := Separator_Character
;
352 elsif Answer
(J
) = 'b' then
357 elsif Pic
.Floater
= '<'
363 for J
in Pic
.End_Float
.. Position
loop -- May be null range.
364 if Answer
(J
) = '9' then
367 elsif Answer
(J
) = '_' then
368 Answer
(J
) := Separator_Character
;
370 elsif Answer
(J
) = 'b' then
375 if Position
> Pic
.End_Float
then
376 Position
:= Pic
.End_Float
;
379 for J
in Pic
.Start_Float
.. Position
- 1 loop
383 Answer
(Position
) := Pic
.Floater
;
384 Sign_Position
:= Position
;
386 elsif Pic
.Floater
= '$' then
388 for J
in Pic
.End_Float
.. Position
loop -- May be null range.
389 if Answer
(J
) = '9' then
392 elsif Answer
(J
) = '_' then
393 Answer
(J
) := ' '; -- no separators before leftmost digit.
395 elsif Answer
(J
) = 'b' then
400 if Position
> Pic
.End_Float
then
401 Position
:= Pic
.End_Float
;
404 for J
in Pic
.Start_Float
.. Position
- 1 loop
408 Answer
(Position
) := Pic
.Floater
;
409 Currency_Pos
:= Position
;
411 elsif Pic
.Floater
= '*' then
413 for J
in Pic
.End_Float
.. Position
loop -- May be null range.
414 if Answer
(J
) = '9' then
417 elsif Answer
(J
) = '_' then
418 Answer
(J
) := Separator_Character
;
420 elsif Answer
(J
) = 'b' then
425 if Position
> Pic
.End_Float
then
426 Position
:= Pic
.End_Float
;
429 for J
in Pic
.Start_Float
.. Position
loop
434 if Pic
.Floater
= '#' then
435 Currency_Pos
:= Currency_Symbol
'Length;
438 for J
in reverse Pic
.Start_Float
.. Position
loop
442 Answer
(J
) := Fill_Character
;
444 when 'Z' |
'b' |
'/' |
'0' =>
450 when '.' |
'V' |
'v' |
'<' |
'$' |
'+' |
'-' =>
454 if Currency_Pos
= 0 then
457 Answer
(J
) := Currency_Symbol
(Currency_Pos
);
458 Currency_Pos
:= Currency_Pos
- 1;
466 Answer
(J
) := Fill_Character
;
472 if Currency_Pos
= 0 then
476 Answer
(J
) := Currency_Symbol
(Currency_Pos
);
477 Currency_Pos
:= Currency_Pos
- 1;
491 if Pic
.Floater
= '#' and then Currency_Pos
/= 0 then
498 if Sign_Position
= Invalid_Position
then
499 if Attrs
.Negative
then
504 if Attrs
.Negative
then
505 case Answer
(Sign_Position
) is
506 when 'C' |
'D' |
'-' =>
510 Answer
(Sign_Position
) := '-';
513 Answer
(Sign_Position
) := '(';
514 Answer
(Pic
.Second_Sign
) := ')';
523 case Answer
(Sign_Position
) is
526 Answer
(Sign_Position
) := ' ';
528 when '<' |
'C' |
'D' =>
529 Answer
(Sign_Position
) := ' ';
530 Answer
(Pic
.Second_Sign
) := ' ';
542 -- Fill in trailing digits
544 if Pic
.Max_Trailing_Digits
> 0 then
546 if Attrs
.Has_Fraction
then
547 Position
:= Attrs
.Start_Of_Fraction
;
548 Last
:= Pic
.Radix_Position
+ 1;
550 for J
in Last
.. Answer
'Last loop
552 if Answer
(J
) = '9' or Answer
(J
) = Pic
.Floater
then
553 Answer
(J
) := Rounded
(Position
);
555 if Rounded
(Position
) /= '0' then
559 Position
:= Position
+ 1;
562 -- Used up fraction but remember place in Answer
564 exit when Position
> Attrs
.End_Of_Fraction
;
566 elsif Answer
(J
) = 'b' then
569 elsif Answer
(J
) = '_' then
570 Answer
(J
) := Separator_Character
;
580 Position
:= Pic
.Radix_Position
+ 1;
583 -- Now fill remaining 9's with zeros and _ with separators
587 for J
in Position
.. Last
loop
588 if Answer
(J
) = '9' then
591 elsif Answer
(J
) = Pic
.Floater
then
594 elsif Answer
(J
) = '_' then
595 Answer
(J
) := Separator_Character
;
597 elsif Answer
(J
) = 'b' then
603 Position
:= Last
+ 1;
606 if Pic
.Floater
= '#' and then Currency_Pos
/= 0 then
610 -- No trailing digits, but now J may need to stick in a currency
613 if Pic
.Start_Currency
= Invalid_Position
then
614 Position
:= Answer
'Last + 1;
616 Position
:= Pic
.Start_Currency
;
620 for J
in Position
.. Answer
'Last loop
622 if Pic
.Start_Currency
/= Invalid_Position
and then
623 Answer
(Pic
.Start_Currency
) = '#' then
627 -- Note: There are some weird cases J can imagine with 'b' or '#'
628 -- in currency strings where the following code will cause
629 -- glitches. The trick is to tell when the character in the
630 -- answer should be checked, and when to look at the original
631 -- string. Some other time. RIE 11/26/96 ???
635 Answer
(J
) := Fill_Character
;
641 if Currency_Pos
> Currency_Symbol
'Length then
645 Answer
(J
) := Currency_Symbol
(Currency_Pos
);
646 Currency_Pos
:= Currency_Pos
+ 1;
654 Answer
(J
) := Fill_Character
;
660 if Currency_Pos
> Currency_Symbol
'Length then
663 Answer
(J
) := Currency_Symbol
(Currency_Pos
);
664 Currency_Pos
:= Currency_Pos
+ 1;
678 -- Now get rid of Blank_when_Zero and complete Star fill.
680 if Zero
and Pic
.Blank_When_Zero
then
682 -- Value is zero, and blank it.
687 Last
:= Last
- 1 + Currency_Symbol
'Length;
690 if Pic
.Radix_Position
/= Invalid_Position
and then
691 Answer
(Pic
.Radix_Position
) = 'V' then
695 return String' (1 .. Last => ' ');
697 elsif Zero and Pic.Star_Fill then
701 Last := Last - 1 + Currency_Symbol'Length;
704 if Pic.Radix_Position /= Invalid_Position then
706 if Answer (Pic.Radix_Position) = 'V
' then
710 if Pic.Radix_Position > Pic.Start_Currency then
711 return String' (1 .. Pic
.Radix_Position
- 1 => '*') &
713 String' (Pic.Radix_Position + 1 .. Last => '*');
719 Pic
.Radix_Position
+ Currency_Symbol
'Length - 2 =>
722 (Pic.Radix_Position + Currency_Symbol'Length .. Last
727 return String' (1 .. Pic
.Radix_Position
- 1 => '*') &
729 String' (Pic.Radix_Position + 1 .. Last => '*');
733 return String' (1 .. Last
=> '*');
736 -- This was once a simple return statement, now there are nine
737 -- different return cases. Not to mention the five above to deal
738 -- with zeros. Why not split things out?
740 -- Processing the radix and sign expansion separately
741 -- would require lots of copying--the string and some of its
742 -- indices--without really simplifying the logic. The cases are:
744 -- 1) Expand $, replace '.' with Radix_Point
745 -- 2) No currency expansion, replace '.' with Radix_Point
746 -- 3) Expand $, radix blanked
747 -- 4) No currency expansion, radix blanked
749 -- 6) Expand $, Elide V
750 -- 7) Elide V, Expand $ (Two cases depending on order.)
751 -- 8) No radix, expand $
752 -- 9) No radix, no currency expansion
754 if Pic
.Radix_Position
/= Invalid_Position
then
756 if Answer
(Pic
.Radix_Position
) = '.' then
757 Answer
(Pic
.Radix_Position
) := Radix_Point
;
761 -- 1) Expand $, replace '.' with Radix_Point
763 return Answer
(1 .. Currency_Pos
- 1) & Currency_Symbol
&
764 Answer
(Currency_Pos
+ 1 .. Answer
'Last);
767 -- 2) No currency expansion, replace '.' with Radix_Point
772 elsif Answer
(Pic
.Radix_Position
) = ' ' then -- blanked radix.
775 -- 3) Expand $, radix blanked
777 return Answer
(1 .. Currency_Pos
- 1) & Currency_Symbol
&
778 Answer
(Currency_Pos
+ 1 .. Answer
'Last);
781 -- 4) No expansion, radix blanked
793 return Answer
(1 .. Pic
.Radix_Position
- 1) &
794 Answer
(Pic
.Radix_Position
+ 1 .. Answer
'Last);
796 elsif Currency_Pos
< Pic
.Radix_Position
then
798 -- 6) Expand $, Elide V
800 return Answer
(1 .. Currency_Pos
- 1) & Currency_Symbol
&
801 Answer
(Currency_Pos
+ 1 .. Pic
.Radix_Position
- 1) &
802 Answer
(Pic
.Radix_Position
+ 1 .. Answer
'Last);
805 -- 7) Elide V, Expand $
807 return Answer
(1 .. Pic
.Radix_Position
- 1) &
808 Answer
(Pic
.Radix_Position
+ 1 .. Currency_Pos
- 1) &
810 Answer
(Currency_Pos
+ 1 .. Answer
'Last);
816 -- 8) No radix, expand $
818 return Answer
(1 .. Currency_Pos
- 1) & Currency_Symbol
&
819 Answer
(Currency_Pos
+ 1 .. Answer
'Last);
822 -- 9) No radix, no currency expansion
829 -------------------------
830 -- Parse_Number_String --
831 -------------------------
833 function Parse_Number_String
(Str
: String) return Number_Attributes
is
834 Answer
: Number_Attributes
;
837 for J
in Str
'Range loop
845 -- Decide if this is the start of a number.
846 -- If so, figure out which one...
848 if Answer
.Has_Fraction
then
849 Answer
.End_Of_Fraction
:= J
;
851 if Answer
.Start_Of_Int
= Invalid_Position
then
853 Answer
.Start_Of_Int
:= J
;
855 Answer
.End_Of_Int
:= J
;
860 -- Only count a zero before the decimal point if it follows a
861 -- non-zero digit. After the decimal point, zeros will be
862 -- counted if followed by a non-zero digit.
864 if not Answer
.Has_Fraction
then
865 if Answer
.Start_Of_Int
/= Invalid_Position
then
866 Answer
.End_Of_Int
:= J
;
874 Answer
.Negative
:= True;
878 -- Close integer, start fraction
880 if Answer
.Has_Fraction
then
884 -- Two decimal points is a no-no.
886 Answer
.Has_Fraction
:= True;
887 Answer
.End_Of_Fraction
:= J
;
889 -- Could leave this at Invalid_Position, but this seems the
890 -- right way to indicate a null range...
892 Answer
.Start_Of_Fraction
:= J
+ 1;
893 Answer
.End_Of_Int
:= J
- 1;
896 raise Picture_Error
; -- can this happen? probably not!
900 if Answer
.Start_Of_Int
= Invalid_Position
then
901 Answer
.Start_Of_Int
:= Answer
.End_Of_Int
+ 1;
904 -- No significant (intger) digits needs a null range.
908 end Parse_Number_String
;
914 -- The following ensures that we return B and not b being careful not
915 -- to break things which expect lower case b for blank. See CXF3A02.
917 function Pic_String
(Pic
: in Picture
) return String is
918 Temp
: String (1 .. Pic
.Contents
.Picture
.Length
) :=
919 Pic
.Contents
.Picture
.Expanded
;
921 for J
in Temp
'Range loop
922 if Temp
(J
) = 'b' then Temp
(J
) := 'B'; end if;
932 procedure Precalculate
(Pic
: in out Format_Record
) is
934 Computed_BWZ
: Boolean := True;
935 Debug
: Boolean := False;
937 type Legality
is (Okay
, Reject
);
938 State
: Legality
:= Reject
;
939 -- Start in reject, which will reject null strings.
941 Index
: Pic_Index
:= Pic
.Picture
.Expanded
'First;
943 function At_End
return Boolean;
944 pragma Inline
(At_End
);
946 procedure Set_State
(L
: Legality
);
947 pragma Inline
(Set_State
);
949 function Look
return Character;
950 pragma Inline
(Look
);
952 function Is_Insert
return Boolean;
953 pragma Inline
(Is_Insert
);
956 pragma Inline
(Skip
);
958 procedure Debug_Start
(Name
: String);
959 pragma Inline
(Debug_Start
);
961 procedure Debug_Integer
(Value
: in Integer; S
: String);
962 pragma Inline
(Debug_Integer
);
964 procedure Trailing_Currency
;
965 procedure Trailing_Bracket
;
966 procedure Number_Fraction
;
967 procedure Number_Completion
;
968 procedure Number_Fraction_Or_Bracket
;
969 procedure Number_Fraction_Or_Z_Fill
;
970 procedure Zero_Suppression
;
971 procedure Floating_Bracket
;
972 procedure Number_Fraction_Or_Star_Fill
;
973 procedure Star_Suppression
;
974 procedure Number_Fraction_Or_Dollar
;
975 procedure Leading_Dollar
;
976 procedure Number_Fraction_Or_Pound
;
977 procedure Leading_Pound
;
979 procedure Floating_Plus
;
980 procedure Floating_Minus
;
981 procedure Picture_Plus
;
982 procedure Picture_Minus
;
983 procedure Picture_Bracket
;
985 procedure Optional_RHS_Sign
;
986 procedure Picture_String
;
992 function At_End
return Boolean is
994 return Index
> Pic
.Picture
.Length
;
1001 procedure Debug_Integer
(Value
: in Integer; S
: String) is
1002 use Ada
.Text_IO
; -- needed for >
1005 if Debug
and then Value
> 0 then
1006 if Ada
.Text_IO
.Col
> 70 - S
'Length then
1007 Ada
.Text_IO
.New_Line
;
1010 Ada
.Text_IO
.Put
(' ' & S
& Integer'Image (Value
) & ',');
1018 procedure Debug_Start
(Name
: String) is
1021 Ada
.Text_IO
.Put_Line
(" In " & Name
& '.');
1025 ----------------------
1026 -- Floating_Bracket --
1027 ----------------------
1029 -- Note that Floating_Bracket is only called with an acceptable
1030 -- prefix. But we don't set Okay, because we must end with a '>'.
1032 procedure Floating_Bracket
is
1034 Debug_Start
("Floating_Bracket");
1036 Pic
.End_Float
:= Index
;
1037 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
1039 -- First bracket wasn't counted...
1050 when '_' |
'0' |
'/' =>
1051 Pic
.End_Float
:= Index
;
1055 Pic
.End_Float
:= Index
;
1056 Pic
.Picture
.Expanded
(Index
) := 'b';
1060 Pic
.End_Float
:= Index
;
1061 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
1073 when 'V' |
'v' |
'.' =>
1074 Pic
.Radix_Position
:= Index
;
1076 Number_Fraction_Or_Bracket
;
1083 end Floating_Bracket
;
1086 --------------------
1087 -- Floating_Minus --
1088 --------------------
1090 procedure Floating_Minus
is
1092 Debug_Start
("Floating_Minus");
1100 when '_' |
'0' |
'/' =>
1101 Pic
.End_Float
:= Index
;
1105 Pic
.End_Float
:= Index
;
1106 Pic
.Picture
.Expanded
(Index
) := 'b';
1110 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
1111 Pic
.End_Float
:= Index
;
1118 when '.' |
'V' |
'v' =>
1119 Pic
.Radix_Position
:= Index
;
1122 while Is_Insert
loop
1139 Pic
.Max_Trailing_Digits
:=
1140 Pic
.Max_Trailing_Digits
+ 1;
1141 Pic
.End_Float
:= Index
;
1144 when '_' |
'0' |
'/' =>
1148 Pic
.Picture
.Expanded
(Index
) := 'b';
1173 procedure Floating_Plus
is
1175 Debug_Start
("Floating_Plus");
1183 when '_' |
'0' |
'/' =>
1184 Pic
.End_Float
:= Index
;
1188 Pic
.End_Float
:= Index
;
1189 Pic
.Picture
.Expanded
(Index
) := 'b';
1193 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
1194 Pic
.End_Float
:= Index
;
1201 when '.' |
'V' |
'v' =>
1202 Pic
.Radix_Position
:= Index
;
1205 while Is_Insert
loop
1222 Pic
.Max_Trailing_Digits
:=
1223 Pic
.Max_Trailing_Digits
+ 1;
1224 Pic
.End_Float
:= Index
;
1227 when '_' |
'0' |
'/' =>
1231 Pic
.Picture
.Expanded
(Index
) := 'b';
1257 function Is_Insert
return Boolean is
1263 case Pic
.Picture
.Expanded
(Index
) is
1265 when '_' |
'0' |
'/' => return True;
1268 Pic
.Picture
.Expanded
(Index
) := 'b'; -- canonical
1271 when others => return False;
1275 --------------------
1276 -- Leading_Dollar --
1277 --------------------
1279 -- Note that Leading_Dollar can be called in either State.
1280 -- It will set state to Okay only if a 9 or (second) $
1283 -- Also notice the tricky bit with State and Zero_Suppression.
1284 -- Zero_Suppression is Picture_Error if a '$' or a '9' has been
1285 -- encountered, exactly the cases where State has been set.
1287 procedure Leading_Dollar
is
1289 Debug_Start
("Leading_Dollar");
1291 -- Treat as a floating dollar, and unwind otherwise.
1294 Pic
.Start_Currency
:= Index
;
1295 Pic
.End_Currency
:= Index
;
1296 Pic
.Start_Float
:= Index
;
1297 Pic
.End_Float
:= Index
;
1299 -- Don't increment Pic.Max_Leading_Digits, we need one "real"
1311 when '_' |
'0' |
'/' =>
1312 Pic
.End_Float
:= Index
;
1315 -- A trailing insertion character is not part of the
1316 -- floating currency, so need to look ahead.
1319 Pic
.End_Float
:= Pic
.End_Float
- 1;
1323 Pic
.End_Float
:= Index
;
1324 Pic
.Picture
.Expanded
(Index
) := 'b';
1328 Pic
.Picture
.Expanded
(Index
) := 'Z'; -- consistency
1330 if State
= Okay
then
1331 raise Picture_Error
;
1333 -- Will overwrite Floater and Start_Float
1339 if State
= Okay
then
1340 raise Picture_Error
;
1342 -- Will overwrite Floater and Start_Float
1348 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
1349 Pic
.End_Float
:= Index
;
1350 Pic
.End_Currency
:= Index
;
1351 Set_State
(Okay
); Skip
;
1354 if State
/= Okay
then
1356 Pic
.Start_Float
:= Invalid_Position
;
1357 Pic
.End_Float
:= Invalid_Position
;
1360 -- A single dollar does not a floating make.
1365 when 'V' |
'v' |
'.' =>
1366 if State
/= Okay
then
1368 Pic
.Start_Float
:= Invalid_Position
;
1369 Pic
.End_Float
:= Invalid_Position
;
1372 -- Only one dollar before the sign is okay,
1373 -- but doesn't float.
1375 Pic
.Radix_Position
:= Index
;
1377 Number_Fraction_Or_Dollar
;
1391 -- This one is complex! A Leading_Pound can be fixed or floating,
1392 -- but in some cases the decision has to be deferred until we leave
1393 -- this procedure. Also note that Leading_Pound can be called in
1396 -- It will set state to Okay only if a 9 or (second) # is
1399 -- One Last note: In ambiguous cases, the currency is treated as
1400 -- floating unless there is only one '#'.
1402 procedure Leading_Pound
is
1404 Inserts
: Boolean := False;
1405 -- Set to True if a '_', '0', '/', 'B', or 'b' is encountered
1407 Must_Float
: Boolean := False;
1408 -- Set to true if a '#' occurs after an insert.
1411 Debug_Start
("Leading_Pound");
1413 -- Treat as a floating currency. If it isn't, this will be
1414 -- overwritten later.
1418 Pic
.Start_Currency
:= Index
;
1419 Pic
.End_Currency
:= Index
;
1420 Pic
.Start_Float
:= Index
;
1421 Pic
.End_Float
:= Index
;
1423 -- Don't increment Pic.Max_Leading_Digits, we need one "real"
1426 Pic
.Max_Currency_Digits
:= 1; -- we've seen one.
1437 when '_' |
'0' |
'/' =>
1438 Pic
.End_Float
:= Index
;
1443 Pic
.Picture
.Expanded
(Index
) := 'b';
1444 Pic
.End_Float
:= Index
;
1449 Pic
.Picture
.Expanded
(Index
) := 'Z'; -- consistency
1452 raise Picture_Error
;
1454 Pic
.Max_Leading_Digits
:= 0;
1456 -- Will overwrite Floater and Start_Float
1463 raise Picture_Error
;
1465 Pic
.Max_Leading_Digits
:= 0;
1467 -- Will overwrite Floater and Start_Float
1477 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
1478 Pic
.End_Float
:= Index
;
1479 Pic
.End_Currency
:= Index
;
1484 if State
/= Okay
then
1486 -- A single '#' doesn't float.
1489 Pic
.Start_Float
:= Invalid_Position
;
1490 Pic
.End_Float
:= Invalid_Position
;
1496 when 'V' |
'v' |
'.' =>
1497 if State
/= Okay
then
1499 Pic
.Start_Float
:= Invalid_Position
;
1500 Pic
.End_Float
:= Invalid_Position
;
1503 -- Only one pound before the sign is okay,
1504 -- but doesn't float.
1506 Pic
.Radix_Position
:= Index
;
1508 Number_Fraction_Or_Pound
;
1521 function Look
return Character is
1524 raise Picture_Error
;
1527 return Pic
.Picture
.Expanded
(Index
);
1536 Debug_Start
("Number");
1541 when '_' |
'0' |
'/' =>
1545 Pic
.Picture
.Expanded
(Index
) := 'b';
1549 Computed_BWZ
:= False;
1550 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
1554 when '.' |
'V' |
'v' =>
1555 Pic
.Radix_Position
:= Index
;
1569 -- Will return in Okay state if a '9' was seen.
1574 -----------------------
1575 -- Number_Completion --
1576 -----------------------
1578 procedure Number_Completion
is
1580 Debug_Start
("Number_Completion");
1582 while not At_End
loop
1585 when '_' |
'0' |
'/' =>
1589 Pic
.Picture
.Expanded
(Index
) := 'b';
1593 Computed_BWZ
:= False;
1594 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
1598 when 'V' |
'v' |
'.' =>
1599 Pic
.Radix_Position
:= Index
;
1608 end Number_Completion
;
1610 ---------------------
1611 -- Number_Fraction --
1612 ---------------------
1614 procedure Number_Fraction
is
1616 -- Note that number fraction can be called in either State.
1617 -- It will set state to Valid only if a 9 is encountered.
1619 Debug_Start
("Number_Fraction");
1627 when '_' |
'0' |
'/' =>
1631 Pic
.Picture
.Expanded
(Index
) := 'b';
1635 Computed_BWZ
:= False;
1636 Pic
.Max_Trailing_Digits
:= Pic
.Max_Trailing_Digits
+ 1;
1637 Set_State
(Okay
); Skip
;
1643 end Number_Fraction
;
1645 --------------------------------
1646 -- Number_Fraction_Or_Bracket --
1647 --------------------------------
1649 procedure Number_Fraction_Or_Bracket
is
1651 Debug_Start
("Number_Fraction_Or_Bracket");
1660 when '_' |
'0' |
'/' => Skip
;
1663 Pic
.Picture
.Expanded
(Index
) := 'b';
1667 Pic
.Max_Trailing_Digits
:= Pic
.Max_Trailing_Digits
+ 1;
1668 Pic
.End_Float
:= Index
;
1677 when '_' |
'0' |
'/' =>
1681 Pic
.Picture
.Expanded
(Index
) := 'b';
1685 Pic
.Max_Trailing_Digits
:=
1686 Pic
.Max_Trailing_Digits
+ 1;
1687 Pic
.End_Float
:= Index
;
1700 end Number_Fraction_Or_Bracket
;
1702 -------------------------------
1703 -- Number_Fraction_Or_Dollar --
1704 -------------------------------
1706 procedure Number_Fraction_Or_Dollar
is
1708 Debug_Start
("Number_Fraction_Or_Dollar");
1716 when '_' |
'0' |
'/' =>
1720 Pic
.Picture
.Expanded
(Index
) := 'b';
1724 Pic
.Max_Trailing_Digits
:= Pic
.Max_Trailing_Digits
+ 1;
1725 Pic
.End_Float
:= Index
;
1734 when '_' |
'0' |
'/' =>
1738 Pic
.Picture
.Expanded
(Index
) := 'b';
1742 Pic
.Max_Trailing_Digits
:=
1743 Pic
.Max_Trailing_Digits
+ 1;
1744 Pic
.End_Float
:= Index
;
1757 end Number_Fraction_Or_Dollar
;
1759 ------------------------------
1760 -- Number_Fraction_Or_Pound --
1761 ------------------------------
1763 procedure Number_Fraction_Or_Pound
is
1772 when '_' |
'0' |
'/' =>
1776 Pic
.Picture
.Expanded
(Index
) := 'b';
1780 Pic
.Max_Trailing_Digits
:= Pic
.Max_Trailing_Digits
+ 1;
1781 Pic
.End_Float
:= Index
;
1791 when '_' |
'0' |
'/' =>
1795 Pic
.Picture
.Expanded
(Index
) := 'b';
1799 Pic
.Max_Trailing_Digits
:=
1800 Pic
.Max_Trailing_Digits
+ 1;
1801 Pic
.End_Float
:= Index
;
1816 end Number_Fraction_Or_Pound
;
1818 ----------------------------------
1819 -- Number_Fraction_Or_Star_Fill --
1820 ----------------------------------
1822 procedure Number_Fraction_Or_Star_Fill
is
1824 Debug_Start
("Number_Fraction_Or_Star_Fill");
1833 when '_' |
'0' |
'/' =>
1837 Pic
.Picture
.Expanded
(Index
) := 'b';
1841 Pic
.Star_Fill
:= True;
1842 Pic
.Max_Trailing_Digits
:= Pic
.Max_Trailing_Digits
+ 1;
1843 Pic
.End_Float
:= Index
;
1853 when '_' |
'0' |
'/' =>
1857 Pic
.Picture
.Expanded
(Index
) := 'b';
1861 Pic
.Star_Fill
:= True;
1862 Pic
.Max_Trailing_Digits
:=
1863 Pic
.Max_Trailing_Digits
+ 1;
1864 Pic
.End_Float
:= Index
;
1878 end Number_Fraction_Or_Star_Fill
;
1880 -------------------------------
1881 -- Number_Fraction_Or_Z_Fill --
1882 -------------------------------
1884 procedure Number_Fraction_Or_Z_Fill
is
1886 Debug_Start
("Number_Fraction_Or_Z_Fill");
1895 when '_' |
'0' |
'/' =>
1899 Pic
.Picture
.Expanded
(Index
) := 'b';
1903 Pic
.Max_Trailing_Digits
:= Pic
.Max_Trailing_Digits
+ 1;
1904 Pic
.End_Float
:= Index
;
1905 Pic
.Picture
.Expanded
(Index
) := 'Z'; -- consistency
1916 when '_' |
'0' |
'/' =>
1920 Pic
.Picture
.Expanded
(Index
) := 'b';
1924 Pic
.Picture
.Expanded
(Index
) := 'Z'; -- consistency
1926 Pic
.Max_Trailing_Digits
:=
1927 Pic
.Max_Trailing_Digits
+ 1;
1928 Pic
.End_Float
:= Index
;
1941 end Number_Fraction_Or_Z_Fill
;
1943 -----------------------
1944 -- Optional_RHS_Sign --
1945 -----------------------
1947 procedure Optional_RHS_Sign
is
1949 Debug_Start
("Optional_RHS_Sign");
1958 Pic
.Sign_Position
:= Index
;
1963 Pic
.Sign_Position
:= Index
;
1964 Pic
.Picture
.Expanded
(Index
) := 'C';
1967 if Look
= 'R' or Look
= 'r' then
1968 Pic
.Second_Sign
:= Index
;
1969 Pic
.Picture
.Expanded
(Index
) := 'R';
1973 raise Picture_Error
;
1979 Pic
.Sign_Position
:= Index
;
1980 Pic
.Picture
.Expanded
(Index
) := 'D';
1983 if Look
= 'B' or Look
= 'b' then
1984 Pic
.Second_Sign
:= Index
;
1985 Pic
.Picture
.Expanded
(Index
) := 'B';
1989 raise Picture_Error
;
1995 if Pic
.Picture
.Expanded
(Pic
.Sign_Position
) = '<' then
1996 Pic
.Second_Sign
:= Index
;
2000 raise Picture_Error
;
2007 end Optional_RHS_Sign
;
2013 -- Note that Picture can be called in either State.
2015 -- It will set state to Valid only if a 9 is encountered or floating
2016 -- currency is called.
2018 procedure Picture
is
2020 Debug_Start
("Picture");
2029 when '_' |
'0' |
'/' =>
2033 Pic
.Picture
.Expanded
(Index
) := 'b';
2045 Computed_BWZ
:= False;
2047 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
2050 when 'V' |
'v' |
'.' =>
2051 Pic
.Radix_Position
:= Index
;
2064 ---------------------
2065 -- Picture_Bracket --
2066 ---------------------
2068 procedure Picture_Bracket
is
2070 Pic
.Sign_Position
:= Index
;
2071 Debug_Start
("Picture_Bracket");
2072 Pic
.Sign_Position
:= Index
;
2074 -- Treat as a floating sign, and unwind otherwise.
2077 Pic
.Start_Float
:= Index
;
2078 Pic
.End_Float
:= Index
;
2080 -- Don't increment Pic.Max_Leading_Digits, we need one "real"
2083 Skip
; -- Known Bracket
2088 when '_' |
'0' |
'/' =>
2089 Pic
.End_Float
:= Index
;
2093 Pic
.End_Float
:= Index
;
2094 Pic
.Picture
.Expanded
(Index
) := 'b';
2098 Set_State
(Okay
); -- "<<>" is enough.
2104 when '$' |
'#' |
'9' |
'*' =>
2105 if State
/= Okay
then
2107 Pic
.Start_Float
:= Invalid_Position
;
2108 Pic
.End_Float
:= Invalid_Position
;
2116 when '.' |
'V' |
'v' =>
2117 if State
/= Okay
then
2119 Pic
.Start_Float
:= Invalid_Position
;
2120 Pic
.End_Float
:= Invalid_Position
;
2123 -- Don't assume that state is okay, haven't seen a digit
2130 raise Picture_Error
;
2134 end Picture_Bracket
;
2140 procedure Picture_Minus
is
2142 Debug_Start
("Picture_Minus");
2144 Pic
.Sign_Position
:= Index
;
2146 -- Treat as a floating sign, and unwind otherwise.
2149 Pic
.Start_Float
:= Index
;
2150 Pic
.End_Float
:= Index
;
2152 -- Don't increment Pic.Max_Leading_Digits, we need one "real"
2155 Skip
; -- Known Minus
2160 when '_' |
'0' |
'/' =>
2161 Pic
.End_Float
:= Index
;
2165 Pic
.End_Float
:= Index
;
2166 Pic
.Picture
.Expanded
(Index
) := 'b';
2170 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
2171 Pic
.End_Float
:= Index
;
2173 Set_State
(Okay
); -- "-- " is enough.
2178 when '$' |
'#' |
'9' |
'*' =>
2179 if State
/= Okay
then
2181 Pic
.Start_Float
:= Invalid_Position
;
2182 Pic
.End_Float
:= Invalid_Position
;
2191 -- Can't have Z and a floating sign.
2193 if State
= Okay
then
2197 Pic
.Picture
.Expanded
(Index
) := 'Z'; -- consistency
2203 when '.' |
'V' |
'v' =>
2204 if State
/= Okay
then
2206 Pic
.Start_Float
:= Invalid_Position
;
2207 Pic
.End_Float
:= Invalid_Position
;
2210 -- Don't assume that state is okay, haven't seen a digit.
2226 procedure Picture_Plus
is
2228 Debug_Start
("Picture_Plus");
2229 Pic
.Sign_Position
:= Index
;
2231 -- Treat as a floating sign, and unwind otherwise.
2234 Pic
.Start_Float
:= Index
;
2235 Pic
.End_Float
:= Index
;
2237 -- Don't increment Pic.Max_Leading_Digits, we need one "real"
2245 when '_' |
'0' |
'/' =>
2246 Pic
.End_Float
:= Index
;
2250 Pic
.End_Float
:= Index
;
2251 Pic
.Picture
.Expanded
(Index
) := 'b';
2255 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
2256 Pic
.End_Float
:= Index
;
2258 Set_State
(Okay
); -- "++" is enough.
2263 when '$' |
'#' |
'9' |
'*' =>
2264 if State
/= Okay
then
2266 Pic
.Start_Float
:= Invalid_Position
;
2267 Pic
.End_Float
:= Invalid_Position
;
2275 if State
= Okay
then
2279 -- Can't have Z and a floating sign.
2281 Pic
.Picture
.Expanded
(Index
) := 'Z'; -- consistency
2283 -- '+Z' is acceptable
2292 when '.' |
'V' |
'v' =>
2293 if State
/= Okay
then
2295 Pic
.Start_Float
:= Invalid_Position
;
2296 Pic
.End_Float
:= Invalid_Position
;
2299 -- Don't assume that state is okay, haven't seen a digit.
2311 --------------------
2312 -- Picture_String --
2313 --------------------
2315 procedure Picture_String
is
2317 Debug_Start
("Picture_String");
2319 while Is_Insert
loop
2339 Pic
.Picture
.Expanded
(Index
) := 'Z'; -- consistency
2349 when '9' |
'.' |
'V' |
'v' =>
2355 raise Picture_Error
;
2359 -- Blank when zero either if the PIC does not contain a '9' or if
2360 -- requested by the user and no '*'
2362 Pic
.Blank_When_Zero
:=
2363 (Computed_BWZ
or Pic
.Blank_When_Zero
) and not Pic
.Star_Fill
;
2365 -- Star fill if '*' and no '9'.
2367 Pic
.Star_Fill
:= Pic
.Star_Fill
and Computed_BWZ
;
2379 procedure Set_State
(L
: Legality
) is
2381 if Debug
then Ada
.Text_IO
.Put_Line
2382 (" Set state from " & Legality
'Image (State
) &
2383 " to " & Legality
'Image (L
));
2395 if Debug
then Ada
.Text_IO
.Put_Line
2396 (" Skip " & Pic
.Picture
.Expanded
(Index
));
2402 ----------------------
2403 -- Star_Suppression --
2404 ----------------------
2406 procedure Star_Suppression
is
2408 Debug_Start
("Star_Suppression");
2410 Pic
.Start_Float
:= Index
;
2411 Pic
.End_Float
:= Index
;
2412 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
2415 -- Even a single * is a valid picture
2417 Pic
.Star_Fill
:= True;
2427 when '_' |
'0' |
'/' =>
2428 Pic
.End_Float
:= Index
;
2432 Pic
.End_Float
:= Index
;
2433 Pic
.Picture
.Expanded
(Index
) := 'b';
2437 Pic
.End_Float
:= Index
;
2438 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
2439 Set_State
(Okay
); Skip
;
2446 when '.' |
'V' |
'v' =>
2447 Pic
.Radix_Position
:= Index
;
2449 Number_Fraction_Or_Star_Fill
;
2457 when others => raise Picture_Error
;
2460 end Star_Suppression
;
2462 ----------------------
2463 -- Trailing_Bracket --
2464 ----------------------
2466 procedure Trailing_Bracket
is
2468 Debug_Start
("Trailing_Bracket");
2471 Pic
.Second_Sign
:= Index
;
2474 raise Picture_Error
;
2476 end Trailing_Bracket
;
2478 -----------------------
2479 -- Trailing_Currency --
2480 -----------------------
2482 procedure Trailing_Currency
is
2484 Debug_Start
("Trailing_Currency");
2491 Pic
.Start_Currency
:= Index
;
2492 Pic
.End_Currency
:= Index
;
2496 while not At_End
and then Look
= '#' loop
2497 if Pic
.Start_Currency
= Invalid_Position
then
2498 Pic
.Start_Currency
:= Index
;
2501 Pic
.End_Currency
:= Index
;
2512 when '_' |
'0' |
'/' => Skip
;
2515 Pic
.Picture
.Expanded
(Index
) := 'b';
2518 when others => return;
2521 end Trailing_Currency
;
2523 ----------------------
2524 -- Zero_Suppression --
2525 ----------------------
2527 procedure Zero_Suppression
is
2529 Debug_Start
("Zero_Suppression");
2532 Pic
.Start_Float
:= Index
;
2533 Pic
.End_Float
:= Index
;
2534 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
2535 Pic
.Picture
.Expanded
(Index
) := 'Z'; -- consistency
2540 -- Even a single Z is a valid picture
2548 when '_' |
'0' |
'/' =>
2549 Pic
.End_Float
:= Index
;
2553 Pic
.End_Float
:= Index
;
2554 Pic
.Picture
.Expanded
(Index
) := 'b';
2558 Pic
.Picture
.Expanded
(Index
) := 'Z'; -- consistency
2560 Pic
.Max_Leading_Digits
:= Pic
.Max_Leading_Digits
+ 1;
2561 Pic
.End_Float
:= Index
;
2570 when '.' |
'V' |
'v' =>
2571 Pic
.Radix_Position
:= Index
;
2573 Number_Fraction_Or_Z_Fill
;
2585 end Zero_Suppression
;
2587 -- Start of processing for Precalculate
2593 Ada
.Text_IO
.New_Line
;
2594 Ada
.Text_IO
.Put
(" Picture : """ &
2595 Pic
.Picture
.Expanded
(1 .. Pic
.Picture
.Length
) & """,");
2596 Ada
.Text_IO
.Put
(" Floater : '" & Pic
.Floater
& "',");
2599 if State
= Reject
then
2600 raise Picture_Error
;
2603 Debug_Integer
(Pic
.Radix_Position
, "Radix Positon : ");
2604 Debug_Integer
(Pic
.Sign_Position
, "Sign Positon : ");
2605 Debug_Integer
(Pic
.Second_Sign
, "Second Sign : ");
2606 Debug_Integer
(Pic
.Start_Float
, "Start Float : ");
2607 Debug_Integer
(Pic
.End_Float
, "End Float : ");
2608 Debug_Integer
(Pic
.Start_Currency
, "Start Currency : ");
2609 Debug_Integer
(Pic
.End_Currency
, "End Currency : ");
2610 Debug_Integer
(Pic
.Max_Leading_Digits
, "Max Leading Digits : ");
2611 Debug_Integer
(Pic
.Max_Trailing_Digits
, "Max Trailing Digits : ");
2614 Ada
.Text_IO
.New_Line
;
2619 when Constraint_Error
=>
2621 -- To deal with special cases like null strings.
2623 raise Picture_Error
;
2632 (Pic_String
: in String;
2633 Blank_When_Zero
: in Boolean := False)
2640 Item
: constant String := Expand
(Pic_String
);
2643 Result
.Contents
.Picture
:= (Item
'Length, Item
);
2644 Result
.Contents
.Original_BWZ
:= Blank_When_Zero
;
2645 Result
.Contents
.Blank_When_Zero
:= Blank_When_Zero
;
2646 Precalculate
(Result
.Contents
);
2652 raise Picture_Error
;
2661 (Pic_String
: in String;
2662 Blank_When_Zero
: in Boolean := False)
2667 Expanded_Pic
: constant String := Expand
(Pic_String
);
2668 -- Raises Picture_Error if Item not well-formed
2670 Format_Rec
: Format_Record
;
2673 Format_Rec
.Picture
:= (Expanded_Pic
'Length, Expanded_Pic
);
2674 Format_Rec
.Blank_When_Zero
:= Blank_When_Zero
;
2675 Format_Rec
.Original_BWZ
:= Blank_When_Zero
;
2676 Precalculate
(Format_Rec
);
2678 -- False only if Blank_When_0 is True but the pic string has a '*'
2680 return not Blank_When_Zero
or
2681 Strings_Fixed
.Index
(Expanded_Pic
, "*") = 0;
2685 when others => return False;
2689 --------------------
2690 -- Decimal_Output --
2691 --------------------
2693 package body Decimal_Output
is
2702 Currency
: in String := Default_Currency
;
2703 Fill
: in Character := Default_Fill
;
2704 Separator
: in Character := Default_Separator
;
2705 Radix_Mark
: in Character := Default_Radix_Mark
)
2709 return Format_Number
2710 (Pic
.Contents
, Num
'Image (Item
),
2711 Currency
, Fill
, Separator
, Radix_Mark
);
2720 Currency
: in String := Default_Currency
)
2723 Picstr
: constant String := Pic_String
(Pic
);
2724 V_Adjust
: Integer := 0;
2725 Cur_Adjust
: Integer := 0;
2728 -- Check if Picstr has 'V' or '$'
2730 -- If 'V', then length is 1 less than otherwise
2732 -- If '$', then length is Currency'Length-1 more than otherwise
2734 -- This should use the string handling package ???
2736 for J
in Picstr
'Range loop
2737 if Picstr
(J
) = 'V' then
2740 elsif Picstr
(J
) = '$' then
2741 Cur_Adjust
:= Currency
'Length - 1;
2745 return Picstr
'Length - V_Adjust
+ Cur_Adjust
;
2753 (File
: in Text_IO
.File_Type
;
2756 Currency
: in String := Default_Currency
;
2757 Fill
: in Character := Default_Fill
;
2758 Separator
: in Character := Default_Separator
;
2759 Radix_Mark
: in Character := Default_Radix_Mark
)
2762 Text_IO
.Put
(File
, Image
(Item
, Pic
,
2763 Currency
, Fill
, Separator
, Radix_Mark
));
2769 Currency
: in String := Default_Currency
;
2770 Fill
: in Character := Default_Fill
;
2771 Separator
: in Character := Default_Separator
;
2772 Radix_Mark
: in Character := Default_Radix_Mark
)
2775 Text_IO
.Put
(Image
(Item
, Pic
,
2776 Currency
, Fill
, Separator
, Radix_Mark
));
2783 Currency
: in String := Default_Currency
;
2784 Fill
: in Character := Default_Fill
;
2785 Separator
: in Character := Default_Separator
;
2786 Radix_Mark
: in Character := Default_Radix_Mark
)
2788 Result
: constant String :=
2789 Image
(Item
, Pic
, Currency
, Fill
, Separator
, Radix_Mark
);
2792 if Result
'Length > To
'Length then
2793 raise Text_IO
.Layout_Error
;
2795 Strings_Fixed
.Move
(Source
=> Result
, Target
=> To
,
2796 Justify
=> Strings
.Right
);
2807 Currency
: in String := Default_Currency
)
2812 Temp
: constant String := Image
(Item
, Pic
, Currency
);
2813 pragma Warnings
(Off
, Temp
);
2819 when Layout_Error
=> return False;
2825 end Ada
.Text_IO
.Editing
;