FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / widechar.adb
blob0c14ceb69062e13be81c2f692ee45202c23ca724
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- W I D E C H A R --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
29 -- --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 -- Note: this package uses the generic subprograms in System.Wch_Cnv, which
36 -- completely encapsulate the set of wide character encoding methods, so no
37 -- modifications are required when adding new encoding methods.
39 with Opt; use Opt;
41 with System.WCh_Cnv; use System.WCh_Cnv;
42 with System.WCh_Con; use System.WCh_Con;
44 package body Widechar is
46 ---------------------------
47 -- Is_Start_Of_Wide_Char --
48 ---------------------------
50 function Is_Start_Of_Wide_Char
51 (S : Source_Buffer_Ptr;
52 P : Source_Ptr)
53 return Boolean
55 begin
56 case Wide_Character_Encoding_Method is
57 when WCEM_Hex =>
58 return S (P) = ASCII.ESC;
60 when WCEM_Upper |
61 WCEM_Shift_JIS |
62 WCEM_EUC |
63 WCEM_UTF8 =>
64 return S (P) >= Character'Val (16#80#);
66 when WCEM_Brackets =>
67 return P <= S'Last - 2
68 and then S (P) = '['
69 and then S (P + 1) = '"'
70 and then S (P + 2) /= '"';
71 end case;
72 end Is_Start_Of_Wide_Char;
74 -----------------
75 -- Length_Wide --
76 -----------------
78 function Length_Wide return Nat is
79 begin
80 return WC_Longest_Sequence;
81 end Length_Wide;
83 ---------------
84 -- Scan_Wide --
85 ---------------
87 procedure Scan_Wide
88 (S : Source_Buffer_Ptr;
89 P : in out Source_Ptr;
90 C : out Char_Code;
91 Err : out Boolean)
93 function In_Char return Character;
94 -- Function to obtain characters of wide character escape sequence
96 function In_Char return Character is
97 begin
98 P := P + 1;
99 return S (P - 1);
100 end In_Char;
102 function WC_In is new Char_Sequence_To_Wide_Char (In_Char);
104 begin
105 C := Char_Code (Wide_Character'Pos
106 (WC_In (In_Char, Wide_Character_Encoding_Method)));
107 Err := False;
109 exception
110 when Constraint_Error =>
111 C := Char_Code (0);
112 P := P - 1;
113 Err := True;
114 end Scan_Wide;
116 --------------
117 -- Set_Wide --
118 --------------
120 procedure Set_Wide
121 (C : Char_Code;
122 S : in out String;
123 P : in out Natural)
125 procedure Out_Char (C : Character);
126 -- Procedure to store one character of wide character sequence
128 procedure Out_Char (C : Character) is
129 begin
130 P := P + 1;
131 S (P) := C;
132 end Out_Char;
134 procedure WC_Out is new Wide_Char_To_Char_Sequence (Out_Char);
136 begin
137 WC_Out (Wide_Character'Val (C), Wide_Character_Encoding_Method);
138 end Set_Wide;
140 ---------------
141 -- Skip_Wide --
142 ---------------
144 procedure Skip_Wide (S : String; P : in out Natural) is
145 function Skip_Char return Character;
146 -- Function to skip one character of wide character escape sequence
148 function Skip_Char return Character is
149 begin
150 P := P + 1;
151 return S (P - 1);
152 end Skip_Char;
154 function WC_Skip is new Char_Sequence_To_Wide_Char (Skip_Char);
156 Discard : Wide_Character;
158 begin
159 Discard := WC_Skip (Skip_Char, Wide_Character_Encoding_Method);
160 end Skip_Wide;
162 end Widechar;