PR c++/29733
[official-gcc.git] / gcc / ada / a-chacon.adb
blob9884337fea74aaaf06207ff1753c5cafaa576631
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . C H A R A C T E R S . H A N D L I N G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2005, Free Software Foundation, Inc. --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 2, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
24 -- Boston, MA 02110-1301, USA. --
25 -- --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
32 -- --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
35 -- --
36 ------------------------------------------------------------------------------
38 package body Ada.Characters.Conversions is
40 ------------------
41 -- Is_Character --
42 ------------------
44 function Is_Character (Item : Wide_Character) return Boolean is
45 begin
46 return Wide_Character'Pos (Item) < 256;
47 end Is_Character;
49 function Is_Character (Item : Wide_Wide_Character) return Boolean is
50 begin
51 return Wide_Wide_Character'Pos (Item) < 256;
52 end Is_Character;
54 ---------------
55 -- Is_String --
56 ---------------
58 function Is_String (Item : Wide_String) return Boolean is
59 begin
60 for J in Item'Range loop
61 if Wide_Character'Pos (Item (J)) >= 256 then
62 return False;
63 end if;
64 end loop;
66 return True;
67 end Is_String;
69 function Is_String (Item : Wide_Wide_String) return Boolean is
70 begin
71 for J in Item'Range loop
72 if Wide_Wide_Character'Pos (Item (J)) >= 256 then
73 return False;
74 end if;
75 end loop;
77 return True;
78 end Is_String;
80 -----------------------
81 -- Is_Wide_Character --
82 -----------------------
84 function Is_Wide_Character (Item : Wide_Wide_Character) return Boolean is
85 begin
86 return Wide_Wide_Character'Pos (Item) < 2**16;
87 end Is_Wide_Character;
89 --------------------
90 -- Is_Wide_String --
91 --------------------
93 function Is_Wide_String (Item : Wide_Wide_String) return Boolean is
94 begin
95 for J in Item'Range loop
96 if Wide_Wide_Character'Pos (Item (J)) >= 2**16 then
97 return False;
98 end if;
99 end loop;
101 return True;
102 end Is_Wide_String;
104 ------------------
105 -- To_Character --
106 ------------------
108 function To_Character
109 (Item : Wide_Character;
110 Substitute : Character := ' ') return Character
112 begin
113 if Is_Character (Item) then
114 return Character'Val (Wide_Character'Pos (Item));
115 else
116 return Substitute;
117 end if;
118 end To_Character;
120 function To_Character
121 (Item : Wide_Wide_Character;
122 Substitute : Character := ' ') return Character
124 begin
125 if Is_Character (Item) then
126 return Character'Val (Wide_Wide_Character'Pos (Item));
127 else
128 return Substitute;
129 end if;
130 end To_Character;
132 ---------------
133 -- To_String --
134 ---------------
136 function To_String
137 (Item : Wide_String;
138 Substitute : Character := ' ') return String
140 Result : String (1 .. Item'Length);
142 begin
143 for J in Item'Range loop
144 Result (J - (Item'First - 1)) := To_Character (Item (J), Substitute);
145 end loop;
147 return Result;
148 end To_String;
150 function To_String
151 (Item : Wide_Wide_String;
152 Substitute : Character := ' ') return String
154 Result : String (1 .. Item'Length);
156 begin
157 for J in Item'Range loop
158 Result (J - (Item'First - 1)) := To_Character (Item (J), Substitute);
159 end loop;
161 return Result;
162 end To_String;
164 -----------------------
165 -- To_Wide_Character --
166 -----------------------
168 function To_Wide_Character
169 (Item : Character) return Wide_Character
171 begin
172 return Wide_Character'Val (Character'Pos (Item));
173 end To_Wide_Character;
175 function To_Wide_Character
176 (Item : Wide_Wide_Character;
177 Substitute : Wide_Character := ' ') return Wide_Character
179 begin
180 if Wide_Wide_Character'Pos (Item) < 2**16 then
181 return Wide_Character'Val (Wide_Wide_Character'Pos (Item));
182 else
183 return Substitute;
184 end if;
185 end To_Wide_Character;
187 --------------------
188 -- To_Wide_String --
189 --------------------
191 function To_Wide_String
192 (Item : String) return Wide_String
194 Result : Wide_String (1 .. Item'Length);
196 begin
197 for J in Item'Range loop
198 Result (J - (Item'First - 1)) := To_Wide_Character (Item (J));
199 end loop;
201 return Result;
202 end To_Wide_String;
204 function To_Wide_String
205 (Item : Wide_Wide_String;
206 Substitute : Wide_Character := ' ') return Wide_String
208 Result : Wide_String (1 .. Item'Length);
210 begin
211 for J in Item'Range loop
212 Result (J - (Item'First - 1)) :=
213 To_Wide_Character (Item (J), Substitute);
214 end loop;
216 return Result;
217 end To_Wide_String;
219 ----------------------------
220 -- To_Wide_Wide_Character --
221 ----------------------------
223 function To_Wide_Wide_Character
224 (Item : Character) return Wide_Wide_Character
226 begin
227 return Wide_Wide_Character'Val (Character'Pos (Item));
228 end To_Wide_Wide_Character;
230 function To_Wide_Wide_Character
231 (Item : Wide_Character) return Wide_Wide_Character
233 begin
234 return Wide_Wide_Character'Val (Wide_Character'Pos (Item));
235 end To_Wide_Wide_Character;
237 -------------------------
238 -- To_Wide_Wide_String --
239 -------------------------
241 function To_Wide_Wide_String
242 (Item : String) return Wide_Wide_String
244 Result : Wide_Wide_String (1 .. Item'Length);
246 begin
247 for J in Item'Range loop
248 Result (J - (Item'First - 1)) := To_Wide_Wide_Character (Item (J));
249 end loop;
251 return Result;
252 end To_Wide_Wide_String;
254 function To_Wide_Wide_String
255 (Item : Wide_String) return Wide_Wide_String
257 Result : Wide_Wide_String (1 .. Item'Length);
259 begin
260 for J in Item'Range loop
261 Result (J - (Item'First - 1)) := To_Wide_Wide_Character (Item (J));
262 end loop;
264 return Result;
265 end To_Wide_Wide_String;
267 end Ada.Characters.Conversions;