1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . C H A R A C T E R S . H A N D L I N G --
9 -- Copyright (C) 2005 Free Software Foundation, Inc. --
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. --
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. --
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. --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
36 ------------------------------------------------------------------------------
38 package body Ada.Characters.Conversions is
44 function Is_Character (Item : Wide_Character) return Boolean is
46 return Wide_Character'Pos (Item) < 256;
49 function Is_Character (Item : Wide_Wide_Character) return Boolean is
51 return Wide_Wide_Character'Pos (Item) < 256;
58 function Is_String (Item : Wide_String) return Boolean is
60 for J in Item'Range loop
61 if Wide_Character'Pos (Item (J)) >= 256 then
69 function Is_String (Item : Wide_Wide_String) return Boolean is
71 for J in Item'Range loop
72 if Wide_Wide_Character'Pos (Item (J)) >= 256 then
80 -----------------------
81 -- Is_Wide_Character --
82 -----------------------
84 function Is_Wide_Character (Item : Wide_Wide_Character) return Boolean is
86 return Wide_Wide_Character'Pos (Item) < 2**16;
87 end Is_Wide_Character;
93 function Is_Wide_String (Item : Wide_Wide_String) return Boolean is
95 for J in Item'Range loop
96 if Wide_Wide_Character'Pos (Item (J)) >= 2**16 then
108 function To_Character
109 (Item : Wide_Character;
110 Substitute : Character := ' ') return Character
113 if Is_Character (Item) then
114 return Character'Val (Wide_Character'Pos (Item));
120 function To_Character
121 (Item : Wide_Wide_Character;
122 Substitute : Character := ' ') return Character
125 if Is_Character (Item) then
126 return Character'Val (Wide_Wide_Character'Pos (Item));
138 Substitute : Character := ' ') return String
140 Result : String (1 .. Item'Length);
143 for J in Item'Range loop
144 Result (J - (Item'First - 1)) := To_Character (Item (J), Substitute);
151 (Item : Wide_Wide_String;
152 Substitute : Character := ' ') return String
154 Result : String (1 .. Item'Length);
157 for J in Item'Range loop
158 Result (J - (Item'First - 1)) := To_Character (Item (J), Substitute);
164 -----------------------
165 -- To_Wide_Character --
166 -----------------------
168 function To_Wide_Character
169 (Item : Character) return Wide_Character
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
180 if Wide_Wide_Character'Pos (Item) < 2**16 then
181 return Wide_Character'Val (Wide_Wide_Character'Pos (Item));
185 end To_Wide_Character;
191 function To_Wide_String
192 (Item : String) return Wide_String
194 Result : Wide_String (1 .. Item'Length);
197 for J in Item'Range loop
198 Result (J - (Item'First - 1)) := To_Wide_Character (Item (J));
204 function To_Wide_String
205 (Item : Wide_Wide_String;
206 Substitute : Wide_Character := ' ') return Wide_String
208 Result : Wide_String (1 .. Item'Length);
211 for J in Item'Range loop
212 Result (J - (Item'First - 1)) :=
213 To_Wide_Character (Item (J), Substitute);
219 ----------------------------
220 -- To_Wide_Wide_Character --
221 ----------------------------
223 function To_Wide_Wide_Character
224 (Item : Character) return Wide_Wide_Character
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
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);
247 for J in Item'Range loop
248 Result (J - (Item'First - 1)) := To_Wide_Wide_Character (Item (J));
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);
260 for J in Item'Range loop
261 Result (J - (Item'First - 1)) := To_Wide_Wide_Character (Item (J));
265 end To_Wide_Wide_String;
267 end Ada.Characters.Conversions;