1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009 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 -- Note: this package uses the generic subprograms in System.Wch_Cnv, which
33 -- completely encapsulate the set of wide character encoding methods, so no
34 -- modifications are required when adding new encoding methods.
38 with System
.WCh_Cnv
; use System
.WCh_Cnv
;
39 with System
.WCh_Con
; use System
.WCh_Con
;
41 package body Widechar
is
43 ---------------------------
44 -- Is_Start_Of_Wide_Char --
45 ---------------------------
47 function Is_Start_Of_Wide_Char
48 (S
: Source_Buffer_Ptr
;
49 P
: Source_Ptr
) return Boolean
52 case Wide_Character_Encoding_Method
is
54 -- For Hex mode, just test for an ESC character. The ESC character
55 -- cannot appear in any other context in a legal Ada program.
58 return S
(P
) = ASCII
.ESC
;
60 -- For brackets, just test ["x where x is a hex character. This is
61 -- sufficient test, since this sequence cannot otherwise appear in a
65 return P
<= S
'Last - 2
67 and then S
(P
+ 1) = '"'
68 and then (S
(P
+ 2) in '0' .. '9'
70 S
(P
+ 2) in 'a' .. 'f'
72 S
(P
+ 2) in 'A' .. 'F');
74 -- All other encoding methods use the upper bit set in the first
75 -- character to uniquely represent a wide character.
81 return S
(P
) >= Character'Val (16#
80#
);
83 end Is_Start_Of_Wide_Char
;
89 function Length_Wide
return Nat
is
91 return WC_Longest_Sequence
;
99 (S
: Source_Buffer_Ptr
;
100 P
: in out Source_Ptr
;
104 P_Init
: constant Source_Ptr
:= P
;
107 function In_Char
return Character;
108 -- Function to obtain characters of wide character escape sequence
114 function In_Char
return Character is
120 function WC_In
is new Char_Sequence_To_UTF_32
(In_Char
);
122 -- Start of processing for Scan_Wide
127 -- Scan out the wide character. If the first character is a bracket,
128 -- we allow brackets encoding regardless of the standard encoding
129 -- method being used, but otherwise we use this standard method.
132 C
:= Char_Code
(WC_In
(Chr
, WCEM_Brackets
));
134 C
:= Char_Code
(WC_In
(Chr
, Wide_Character_Encoding_Method
));
138 Wide_Char_Byte_Count
:= Wide_Char_Byte_Count
+ Nat
(P
- P_Init
- 1);
141 when Constraint_Error
=>
156 procedure Out_Char
(C
: Character);
157 -- Procedure to store one character of wide character sequence
163 procedure Out_Char
(C
: Character) is
169 procedure WC_Out
is new UTF_32_To_Char_Sequence
(Out_Char
);
171 -- Start of processing for Set_Wide
174 WC_Out
(UTF_32_Code
(C
), Wide_Character_Encoding_Method
);
181 procedure Skip_Wide
(S
: String; P
: in out Natural) is
182 P_Init
: constant Natural := P
;
184 function Skip_Char
return Character;
185 -- Function to skip one character of wide character escape sequence
191 function Skip_Char
return Character is
197 function WC_Skip
is new Char_Sequence_To_UTF_32
(Skip_Char
);
199 Discard
: UTF_32_Code
;
200 pragma Warnings
(Off
, Discard
);
202 -- Start of processing for Skip_Wide
205 Discard
:= WC_Skip
(Skip_Char
, Wide_Character_Encoding_Method
);
206 Wide_Char_Byte_Count
:= Wide_Char_Byte_Count
+ Nat
(P
- P_Init
- 1);
213 procedure Skip_Wide
(S
: Source_Buffer_Ptr
; P
: in out Source_Ptr
) is
214 P_Init
: constant Source_Ptr
:= P
;
216 function Skip_Char
return Character;
217 -- Function to skip one character of wide character escape sequence
223 function Skip_Char
return Character is
229 function WC_Skip
is new Char_Sequence_To_UTF_32
(Skip_Char
);
231 Discard
: UTF_32_Code
;
232 pragma Warnings
(Off
, Discard
);
234 -- Start of processing for Skip_Wide
237 Discard
:= WC_Skip
(Skip_Char
, Wide_Character_Encoding_Method
);
238 Wide_Char_Byte_Count
:= Wide_Char_Byte_Count
+ Nat
(P
- P_Init
- 1);