1 |
12 |
jlechner |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT RUN-TIME COMPONENTS --
|
4 |
|
|
-- --
|
5 |
|
|
-- S Y S T E M . W C H _ W T S --
|
6 |
|
|
-- --
|
7 |
|
|
-- B o d y --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
|
10 |
|
|
-- --
|
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. --
|
21 |
|
|
-- --
|
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. --
|
28 |
|
|
-- --
|
29 |
|
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
30 |
|
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
31 |
|
|
-- --
|
32 |
|
|
------------------------------------------------------------------------------
|
33 |
|
|
|
34 |
|
|
with System.WCh_Con; use System.WCh_Con;
|
35 |
|
|
with System.WCh_Cnv; use System.WCh_Cnv;
|
36 |
|
|
|
37 |
|
|
package body System.WCh_WtS is
|
38 |
|
|
|
39 |
|
|
-----------------------
|
40 |
|
|
-- Local Subprograms --
|
41 |
|
|
-----------------------
|
42 |
|
|
|
43 |
|
|
procedure Store_UTF_32_Character
|
44 |
|
|
(U : UTF_32_Code;
|
45 |
|
|
S : out String;
|
46 |
|
|
P : in out Integer;
|
47 |
|
|
EM : WC_Encoding_Method);
|
48 |
|
|
-- Stores the string representation of the wide or wide wide character
|
49 |
|
|
-- whose code is given as U, starting at S (P + 1). P is incremented to
|
50 |
|
|
-- point to the last character stored. Raises CE if character cannot be
|
51 |
|
|
-- stored using the given encoding method.
|
52 |
|
|
|
53 |
|
|
----------------------------
|
54 |
|
|
-- Store_UTF_32_Character --
|
55 |
|
|
----------------------------
|
56 |
|
|
|
57 |
|
|
procedure Store_UTF_32_Character
|
58 |
|
|
(U : UTF_32_Code;
|
59 |
|
|
S : out String;
|
60 |
|
|
P : in out Integer;
|
61 |
|
|
EM : WC_Encoding_Method)
|
62 |
|
|
is
|
63 |
|
|
procedure Out_Char (C : Character);
|
64 |
|
|
pragma Inline (Out_Char);
|
65 |
|
|
-- Procedure to increment P and store C at S (P)
|
66 |
|
|
|
67 |
|
|
procedure Store_Chars is new UTF_32_To_Char_Sequence (Out_Char);
|
68 |
|
|
|
69 |
|
|
--------------
|
70 |
|
|
-- Out_Char --
|
71 |
|
|
--------------
|
72 |
|
|
|
73 |
|
|
procedure Out_Char (C : Character) is
|
74 |
|
|
begin
|
75 |
|
|
P := P + 1;
|
76 |
|
|
S (P) := C;
|
77 |
|
|
end Out_Char;
|
78 |
|
|
|
79 |
|
|
begin
|
80 |
|
|
Store_Chars (U, EM);
|
81 |
|
|
end Store_UTF_32_Character;
|
82 |
|
|
|
83 |
|
|
---------------------------
|
84 |
|
|
-- Wide_String_To_String --
|
85 |
|
|
---------------------------
|
86 |
|
|
|
87 |
|
|
function Wide_String_To_String
|
88 |
|
|
(S : Wide_String;
|
89 |
|
|
EM : WC_Encoding_Method) return String
|
90 |
|
|
is
|
91 |
|
|
R : String (1 .. 5 * S'Length); -- worst case length!
|
92 |
|
|
RP : Natural;
|
93 |
|
|
|
94 |
|
|
begin
|
95 |
|
|
RP := 0;
|
96 |
|
|
for SP in S'Range loop
|
97 |
|
|
Store_UTF_32_Character (Wide_Character'Pos (S (SP)), R, RP, EM);
|
98 |
|
|
end loop;
|
99 |
|
|
|
100 |
|
|
return R (1 .. RP);
|
101 |
|
|
end Wide_String_To_String;
|
102 |
|
|
|
103 |
|
|
--------------------------------
|
104 |
|
|
-- Wide_Wide_Sring_To_String --
|
105 |
|
|
--------------------------------
|
106 |
|
|
|
107 |
|
|
function Wide_Wide_String_To_String
|
108 |
|
|
(S : Wide_Wide_String;
|
109 |
|
|
EM : WC_Encoding_Method) return String
|
110 |
|
|
is
|
111 |
|
|
R : String (1 .. 7 * S'Length); -- worst case length!
|
112 |
|
|
RP : Natural;
|
113 |
|
|
|
114 |
|
|
begin
|
115 |
|
|
RP := 0;
|
116 |
|
|
|
117 |
|
|
for SP in S'Range loop
|
118 |
|
|
Store_UTF_32_Character (Wide_Wide_Character'Pos (S (SP)), R, RP, EM);
|
119 |
|
|
end loop;
|
120 |
|
|
|
121 |
|
|
return R (1 .. RP);
|
122 |
|
|
end Wide_Wide_String_To_String;
|
123 |
|
|
|
124 |
|
|
end System.WCh_WtS;
|