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-2012, 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 package body Ada
.Characters
.Conversions
is
38 function Is_Character
(Item
: Wide_Character) return Boolean is
40 return Wide_Character'Pos (Item
) < 256;
43 function Is_Character
(Item
: Wide_Wide_Character
) return Boolean is
45 return Wide_Wide_Character
'Pos (Item
) < 256;
52 function Is_String
(Item
: Wide_String) return Boolean is
54 for J
in Item
'Range loop
55 if Wide_Character'Pos (Item
(J
)) >= 256 then
63 function Is_String
(Item
: Wide_Wide_String
) return Boolean is
65 for J
in Item
'Range loop
66 if Wide_Wide_Character
'Pos (Item
(J
)) >= 256 then
74 -----------------------
75 -- Is_Wide_Character --
76 -----------------------
78 function Is_Wide_Character
(Item
: Wide_Wide_Character
) return Boolean is
80 return Wide_Wide_Character
'Pos (Item
) < 2**16;
81 end Is_Wide_Character
;
87 function Is_Wide_String
(Item
: Wide_Wide_String
) return Boolean is
89 for J
in Item
'Range loop
90 if Wide_Wide_Character
'Pos (Item
(J
)) >= 2**16 then
102 function To_Character
103 (Item
: Wide_Character;
104 Substitute
: Character := ' ') return Character
107 if Is_Character
(Item
) then
108 return Character'Val (Wide_Character'Pos (Item
));
114 function To_Character
115 (Item
: Wide_Wide_Character
;
116 Substitute
: Character := ' ') return Character
119 if Is_Character
(Item
) then
120 return Character'Val (Wide_Wide_Character
'Pos (Item
));
132 Substitute
: Character := ' ') return String
134 Result
: String (1 .. Item
'Length);
137 for J
in Item
'Range loop
138 Result
(J
- (Item
'First - 1)) := To_Character
(Item
(J
), Substitute
);
145 (Item
: Wide_Wide_String
;
146 Substitute
: Character := ' ') return String
148 Result
: String (1 .. Item
'Length);
151 for J
in Item
'Range loop
152 Result
(J
- (Item
'First - 1)) := To_Character
(Item
(J
), Substitute
);
158 -----------------------
159 -- To_Wide_Character --
160 -----------------------
162 function To_Wide_Character
163 (Item
: Character) return Wide_Character
166 return Wide_Character'Val (Character'Pos (Item
));
167 end To_Wide_Character
;
169 function To_Wide_Character
170 (Item
: Wide_Wide_Character
;
171 Substitute
: Wide_Character := ' ') return Wide_Character
174 if Wide_Wide_Character
'Pos (Item
) < 2**16 then
175 return Wide_Character'Val (Wide_Wide_Character
'Pos (Item
));
179 end To_Wide_Character
;
185 function To_Wide_String
186 (Item
: String) return Wide_String
188 Result
: Wide_String (1 .. Item
'Length);
191 for J
in Item
'Range loop
192 Result
(J
- (Item
'First - 1)) := To_Wide_Character
(Item
(J
));
198 function To_Wide_String
199 (Item
: Wide_Wide_String
;
200 Substitute
: Wide_Character := ' ') return Wide_String
202 Result
: Wide_String (1 .. Item
'Length);
205 for J
in Item
'Range loop
206 Result
(J
- (Item
'First - 1)) :=
207 To_Wide_Character
(Item
(J
), Substitute
);
213 ----------------------------
214 -- To_Wide_Wide_Character --
215 ----------------------------
217 function To_Wide_Wide_Character
218 (Item
: Character) return Wide_Wide_Character
221 return Wide_Wide_Character
'Val (Character'Pos (Item
));
222 end To_Wide_Wide_Character
;
224 function To_Wide_Wide_Character
225 (Item
: Wide_Character) return Wide_Wide_Character
228 return Wide_Wide_Character
'Val (Wide_Character'Pos (Item
));
229 end To_Wide_Wide_Character
;
231 -------------------------
232 -- To_Wide_Wide_String --
233 -------------------------
235 function To_Wide_Wide_String
236 (Item
: String) return Wide_Wide_String
238 Result
: Wide_Wide_String
(1 .. Item
'Length);
241 for J
in Item
'Range loop
242 Result
(J
- (Item
'First - 1)) := To_Wide_Wide_Character
(Item
(J
));
246 end To_Wide_Wide_String
;
248 function To_Wide_Wide_String
249 (Item
: Wide_String) return Wide_Wide_String
251 Result
: Wide_Wide_String
(1 .. Item
'Length);
254 for J
in Item
'Range loop
255 Result
(J
- (Item
'First - 1)) := To_Wide_Wide_Character
(Item
(J
));
259 end To_Wide_Wide_String
;
261 end Ada
.Characters
.Conversions
;