1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- ADA.WIDE_WIDE_TEXT_IO.ENUMERATION_AUX --
9 -- Copyright (C) 1992-2012, 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 3, 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Ada
.Wide_Wide_Text_IO
.Generic_Aux
; use Ada
.Wide_Wide_Text_IO
.Generic_Aux
;
33 with Ada
.Characters
.Conversions
; use Ada
.Characters
.Conversions
;
34 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
35 with Interfaces
.C_Streams
; use Interfaces
.C_Streams
;
36 with System
.WCh_Con
; use System
.WCh_Con
;
38 package body Ada
.Wide_Wide_Text_IO
.Enumeration_Aux
is
40 subtype TFT
is Ada
.Wide_Wide_Text_IO
.File_Type
;
41 -- File type required for calls to routines in Aux
43 -----------------------
44 -- Local Subprograms --
45 -----------------------
48 (WC
: Wide_Wide_Character
;
49 Buf
: out Wide_Wide_String
;
50 Ptr
: in out Integer);
51 -- Store a single character in buffer, checking for overflow
53 -- These definitions replace the ones in Ada.Characters.Handling, which
54 -- do not seem to work for some strange not understood reason ??? at
55 -- least in the OS/2 version.
57 function To_Lower
(C
: Character) return Character;
63 procedure Get_Enum_Lit
65 Buf
: out Wide_Wide_String
;
69 WC
: Wide_Wide_Character
;
73 Load_Skip
(TFT
(File
));
74 ch
:= Nextc
(TFT
(File
));
76 -- Character literal case. If the initial character is a quote, then
77 -- we read as far as we can without backup (see ACVC test CE3905L)
79 if ch
= Character'Pos (''') then
81 Store_Char
(WC
, Buf
, Buflen
);
83 ch
:= Nextc
(TFT
(File
));
85 if ch
= LM
or else ch
= EOF
then
90 Store_Char
(WC
, Buf
, Buflen
);
92 ch
:= Nextc
(TFT
(File
));
94 if ch
/= Character'Pos (''') then
99 Store_Char
(WC
, Buf
, Buflen
);
101 -- Similarly for identifiers, read as far as we can, in particular,
102 -- do read a trailing underscore (again see ACVC test CE3905L to
103 -- understand why we do this, although it seems somewhat peculiar).
106 -- Identifier must start with a letter. Any wide character value
107 -- outside the normal Latin-1 range counts as a letter for this.
109 if ch
< 255 and then not Is_Letter
(Character'Val (ch
)) then
113 -- If we do have a letter, loop through the characters quitting on
114 -- the first non-identifier character (note that this includes the
115 -- cases of hitting a line mark or page mark).
119 Store_Char
(WC
, Buf
, Buflen
);
121 ch
:= Nextc
(TFT
(File
));
125 if ch
= Character'Pos ('_') then
126 exit when Buf
(Buflen
) = '_';
128 elsif ch
= Character'Pos (ASCII
.ESC
) then
131 elsif File
.WC_Method
in WC_Upper_Half_Encoding_Method
137 exit when not Is_Letter
(Character'Val (ch
))
139 not Is_Digit
(Character'Val (ch
));
151 Item
: Wide_Wide_String
;
155 Actual_Width
: constant Integer :=
156 Integer'Max (Integer (Width
), Item
'Length);
159 Check_On_One_Line
(TFT
(File
), Actual_Width
);
161 if Set
= Lower_Case
and then Item
(Item
'First) /= ''' then
163 Iteml
: Wide_Wide_String
(Item
'First .. Item
'Last);
166 for J
in Item
'Range loop
167 if Is_Character
(Item
(J
)) then
169 To_Wide_Wide_Character
170 (To_Lower
(To_Character
(Item
(J
))));
172 Iteml
(J
) := Item
(J
);
183 for J
in 1 .. Actual_Width
- Item
'Length loop
193 (To
: out Wide_Wide_String
;
194 Item
: Wide_Wide_String
;
200 if Item
'Length > To
'Length then
205 for J
in Item
'Range loop
207 and then Item
(Item
'First) /= '''
208 and then Is_Character
(Item
(J
))
211 To_Wide_Wide_Character
(To_Lower
(To_Character
(Item
(J
))));
213 To
(Ptr
) := Item
(J
);
219 while Ptr
<= To
'Last loop
230 procedure Scan_Enum_Lit
231 (From
: Wide_Wide_String
;
235 WC
: Wide_Wide_Character
;
237 -- Processing for Scan_Enum_Lit
243 if Start
> From
'Last then
246 elsif Is_Character
(From
(Start
))
247 and then not Is_Blank
(To_Character
(From
(Start
)))
256 -- Character literal case. If the initial character is a quote, then
257 -- we read as far as we can without backup (see ACVC test CE3905L
258 -- which is for the analogous case for reading from a file).
260 if From
(Start
) = ''' then
263 if Stop
= From
'Last then
269 if From
(Stop
) in ' ' .. '~'
270 or else From
(Stop
) >= Wide_Wide_Character
'Val (16#
80#
)
272 if Stop
= From
'Last then
277 if From
(Stop
) = ''' then
285 -- Similarly for identifiers, read as far as we can, in particular,
286 -- do read a trailing underscore (again see ACVC test CE3905L to
287 -- understand why we do this, although it seems somewhat peculiar).
290 -- Identifier must start with a letter, any wide character outside
291 -- the normal Latin-1 range is considered a letter for this test.
293 if Is_Character
(From
(Start
))
294 and then not Is_Letter
(To_Character
(From
(Start
)))
299 -- If we do have a letter, loop through the characters quitting on
300 -- the first non-identifier character (note that this includes the
301 -- cases of hitting a line mark or page mark).
304 while Stop
< From
'Last loop
305 WC
:= From
(Stop
+ 1);
310 not Is_Letter
(To_Character
(WC
))
312 not Is_Letter
(To_Character
(WC
))
314 (WC
/= '_' or else From
(Stop
- 1) = '_');
327 (WC
: Wide_Wide_Character
;
328 Buf
: out Wide_Wide_String
;
329 Ptr
: in out Integer)
332 if Ptr
= Buf
'Last then
344 function To_Lower
(C
: Character) return Character is
346 if C
in 'A' .. 'Z' then
347 return Character'Val (Character'Pos (C
) + 32);
353 end Ada
.Wide_Wide_Text_IO
.Enumeration_Aux
;