1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . C H A R A C T E R S . C O N V E R S I O N S --
9 -- Copyright (C) 2005-2006, 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 package body Ada
.Characters
.Conversions
is
40 function Is_Character
(Item
: Wide_Character) return Boolean is
42 return Wide_Character'Pos (Item
) < 256;
45 function Is_Character
(Item
: Wide_Wide_Character
) return Boolean is
47 return Wide_Wide_Character
'Pos (Item
) < 256;
54 function Is_String
(Item
: Wide_String) return Boolean is
56 for J
in Item
'Range loop
57 if Wide_Character'Pos (Item
(J
)) >= 256 then
65 function Is_String
(Item
: Wide_Wide_String
) return Boolean is
67 for J
in Item
'Range loop
68 if Wide_Wide_Character
'Pos (Item
(J
)) >= 256 then
76 -----------------------
77 -- Is_Wide_Character --
78 -----------------------
80 function Is_Wide_Character
(Item
: Wide_Wide_Character
) return Boolean is
82 return Wide_Wide_Character
'Pos (Item
) < 2**16;
83 end Is_Wide_Character
;
89 function Is_Wide_String
(Item
: Wide_Wide_String
) return Boolean is
91 for J
in Item
'Range loop
92 if Wide_Wide_Character
'Pos (Item
(J
)) >= 2**16 then
104 function To_Character
105 (Item
: Wide_Character;
106 Substitute
: Character := ' ') return Character
109 if Is_Character
(Item
) then
110 return Character'Val (Wide_Character'Pos (Item
));
116 function To_Character
117 (Item
: Wide_Wide_Character
;
118 Substitute
: Character := ' ') return Character
121 if Is_Character
(Item
) then
122 return Character'Val (Wide_Wide_Character
'Pos (Item
));
134 Substitute
: Character := ' ') return String
136 Result
: String (1 .. Item
'Length);
139 for J
in Item
'Range loop
140 Result
(J
- (Item
'First - 1)) := To_Character
(Item
(J
), Substitute
);
147 (Item
: Wide_Wide_String
;
148 Substitute
: Character := ' ') return String
150 Result
: String (1 .. Item
'Length);
153 for J
in Item
'Range loop
154 Result
(J
- (Item
'First - 1)) := To_Character
(Item
(J
), Substitute
);
160 -----------------------
161 -- To_Wide_Character --
162 -----------------------
164 function To_Wide_Character
165 (Item
: Character) return Wide_Character
168 return Wide_Character'Val (Character'Pos (Item
));
169 end To_Wide_Character
;
171 function To_Wide_Character
172 (Item
: Wide_Wide_Character
;
173 Substitute
: Wide_Character := ' ') return Wide_Character
176 if Wide_Wide_Character
'Pos (Item
) < 2**16 then
177 return Wide_Character'Val (Wide_Wide_Character
'Pos (Item
));
181 end To_Wide_Character
;
187 function To_Wide_String
188 (Item
: String) return Wide_String
190 Result
: Wide_String (1 .. Item
'Length);
193 for J
in Item
'Range loop
194 Result
(J
- (Item
'First - 1)) := To_Wide_Character
(Item
(J
));
200 function To_Wide_String
201 (Item
: Wide_Wide_String
;
202 Substitute
: Wide_Character := ' ') return Wide_String
204 Result
: Wide_String (1 .. Item
'Length);
207 for J
in Item
'Range loop
208 Result
(J
- (Item
'First - 1)) :=
209 To_Wide_Character
(Item
(J
), Substitute
);
215 ----------------------------
216 -- To_Wide_Wide_Character --
217 ----------------------------
219 function To_Wide_Wide_Character
220 (Item
: Character) return Wide_Wide_Character
223 return Wide_Wide_Character
'Val (Character'Pos (Item
));
224 end To_Wide_Wide_Character
;
226 function To_Wide_Wide_Character
227 (Item
: Wide_Character) return Wide_Wide_Character
230 return Wide_Wide_Character
'Val (Wide_Character'Pos (Item
));
231 end To_Wide_Wide_Character
;
233 -------------------------
234 -- To_Wide_Wide_String --
235 -------------------------
237 function To_Wide_Wide_String
238 (Item
: String) return Wide_Wide_String
240 Result
: Wide_Wide_String
(1 .. Item
'Length);
243 for J
in Item
'Range loop
244 Result
(J
- (Item
'First - 1)) := To_Wide_Wide_Character
(Item
(J
));
248 end To_Wide_Wide_String
;
250 function To_Wide_Wide_String
251 (Item
: Wide_String) return Wide_Wide_String
253 Result
: Wide_Wide_String
(1 .. Item
'Length);
256 for J
in Item
'Range loop
257 Result
(J
- (Item
'First - 1)) := To_Wide_Wide_Character
(Item
(J
));
261 end To_Wide_Wide_String
;
263 end Ada
.Characters
.Conversions
;