PR libgomp/25884
[official-gcc.git] / gcc / ada / s-wchwts.adb
blob995f5acda0ffd936d33b3910625a2835a827f5c3
1 ------------------------------------------------------------------------------
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 ------------------------------------------------------------------------------
34 with System.WCh_Con; use System.WCh_Con;
35 with System.WCh_Cnv; use System.WCh_Cnv;
37 package body System.WCh_WtS is
39 -----------------------
40 -- Local Subprograms --
41 -----------------------
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.
53 ----------------------------
54 -- Store_UTF_32_Character --
55 ----------------------------
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)
63 procedure Out_Char (C : Character);
64 pragma Inline (Out_Char);
65 -- Procedure to increment P and store C at S (P)
67 procedure Store_Chars is new UTF_32_To_Char_Sequence (Out_Char);
69 --------------
70 -- Out_Char --
71 --------------
73 procedure Out_Char (C : Character) is
74 begin
75 P := P + 1;
76 S (P) := C;
77 end Out_Char;
79 begin
80 Store_Chars (U, EM);
81 end Store_UTF_32_Character;
83 ---------------------------
84 -- Wide_String_To_String --
85 ---------------------------
87 function Wide_String_To_String
88 (S : Wide_String;
89 EM : WC_Encoding_Method) return String
91 R : String (1 .. 5 * S'Length); -- worst case length!
92 RP : Natural;
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;
100 return R (1 .. RP);
101 end Wide_String_To_String;
103 --------------------------------
104 -- Wide_Wide_Sring_To_String --
105 --------------------------------
107 function Wide_Wide_String_To_String
108 (S : Wide_Wide_String;
109 EM : WC_Encoding_Method) return String
111 R : String (1 .. 7 * S'Length); -- worst case length!
112 RP : Natural;
114 begin
115 RP := 0;
117 for SP in S'Range loop
118 Store_UTF_32_Character (Wide_Wide_Character'Pos (S (SP)), R, RP, EM);
119 end loop;
121 return R (1 .. RP);
122 end Wide_Wide_String_To_String;
124 end System.WCh_WtS;