1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . V A L _ U T I L --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 with GNAT.Case_Util; use GNAT.Case_Util;
38 package body System.Val_Util is
40 ----------------------
41 -- Normalize_String --
42 ----------------------
44 procedure Normalize_String
52 -- Scan for leading spaces
54 while F <= L and then S (F) = ' ' loop
58 -- Check for case when the string contained no characters
61 raise Constraint_Error;
64 -- Scan for trailing spaces
66 while S (L) = ' ' loop
70 -- Except in the case of a character literal, convert to upper case
74 S (J) := To_Upper (S (J));
84 function Scan_Exponent
88 Real : Boolean := False)
91 P : Natural := Ptr.all;
97 or else (Str (P) /= 'E' and then Str (P) /= 'e')
102 -- We have an E/e, see if sign follows
106 if Str (P) = '+' then
115 elsif Str (P) = '-' then
118 if P > Max or else not Real then
128 if Str (P) not in '0' .. '9' then
132 -- Scan out the exponent value as an unsigned integer. Values larger
133 -- than (Integer'Last / 10) are simply considered large enough here.
134 -- This assumption is correct for all machines we know of (e.g. in
135 -- the case of 16 bit integers it allows exponents up to 3276, which
136 -- is large enough for the largest floating types in base 2.)
141 if X < (Integer'Last / 10) then
142 X := X * 10 + (Character'Pos (Str (P)) - Character'Pos ('0'));
149 if Str (P) = '_' then
150 Scan_Underscore (Str, P, Ptr, Max, False);
152 exit when Str (P) not in '0' .. '9';
171 Ptr : access Integer;
174 Start : out Positive)
176 P : Natural := Ptr.all;
179 -- Deal with case of null string (all blanks!). As per spec, we
180 -- raise constraint error, with Ptr unchanged, and thus > Max.
183 raise Constraint_Error;
186 -- Scan past initial blanks
188 while Str (P) = ' ' loop
193 raise Constraint_Error;
199 -- Remember an initial minus sign
201 if Str (P) = '-' then
207 raise Constraint_Error;
210 -- Skip past an initial plus sign
212 elsif Str (P) = '+' then
218 raise Constraint_Error;
228 --------------------------
229 -- Scan_Trailing_Blanks --
230 --------------------------
232 procedure Scan_Trailing_Blanks (Str : String; P : Positive) is
234 for J in P .. Str'Last loop
235 if Str (J) /= ' ' then
236 raise Constraint_Error;
239 end Scan_Trailing_Blanks;
241 ---------------------
242 -- Scan_Underscore --
243 ---------------------
245 procedure Scan_Underscore
248 Ptr : access Integer;
257 -- If underscore is at the end of string, then this is an error and
258 -- we raise Constraint_Error, leaving the pointer past the undescore.
259 -- This seems a bit strange. It means e,g, that if the field is:
263 -- that Constraint_Error is raised. You might think that the RM in
264 -- this case would scan out the 345 as a valid integer, leaving the
265 -- pointer at the underscore, but the ACVC suite clearly requires
266 -- an error in this situation (see for example CE3704M).
270 raise Constraint_Error;
273 -- Similarly, if no digit follows the underscore raise an error. This
274 -- also catches the case of double underscore which is also an error.
280 (Ext and then (C in 'A' .. 'F' or else C in 'a' .. 'f'))
285 raise Constraint_Error;