1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . W C H _ W T S --
9 -- Copyright (C) 1992-2017, 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 with System
.WCh_Con
; use System
.WCh_Con
;
33 with System
.WCh_Cnv
; use System
.WCh_Cnv
;
35 package body System
.WCh_WtS
is
37 -----------------------
38 -- Local Subprograms --
39 -----------------------
41 procedure Store_UTF_32_Character
45 EM
: WC_Encoding_Method
);
46 -- Stores the string representation of the wide or wide wide character
47 -- whose code is given as U, starting at S (P + 1). P is incremented to
48 -- point to the last character stored. Raises CE if character cannot be
49 -- stored using the given encoding method.
51 ----------------------------
52 -- Store_UTF_32_Character --
53 ----------------------------
55 procedure Store_UTF_32_Character
59 EM
: WC_Encoding_Method
)
61 procedure Out_Char
(C
: Character);
62 pragma Inline
(Out_Char
);
63 -- Procedure to increment P and store C at S (P)
65 procedure Store_Chars
is new UTF_32_To_Char_Sequence
(Out_Char
);
71 procedure Out_Char
(C
: Character) is
79 end Store_UTF_32_Character
;
81 ---------------------------
82 -- Wide_String_To_String --
83 ---------------------------
85 function Wide_String_To_String
87 EM
: WC_Encoding_Method
) return String
89 R
: String (S
'First .. S
'First + 5 * S
'Length); -- worst case length
94 for SP
in S
'Range loop
95 Store_UTF_32_Character
(Wide_Character'Pos (S
(SP
)), R
, RP
, EM
);
98 return R
(R
'First .. RP
);
99 end Wide_String_To_String
;
101 --------------------------------
102 -- Wide_Wide_String_To_String --
103 --------------------------------
105 function Wide_Wide_String_To_String
106 (S
: Wide_Wide_String
;
107 EM
: WC_Encoding_Method
) return String
109 R
: String (S
'First .. S
'First + 7 * S
'Length); -- worst case length
115 for SP
in S
'Range loop
116 Store_UTF_32_Character
(Wide_Wide_Character
'Pos (S
(SP
)), R
, RP
, EM
);
119 return R
(R
'First .. RP
);
120 end Wide_Wide_String_To_String
;