1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . W C H _ S T W --
9 -- Copyright (C) 1992-2018, 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_StW
is
37 -----------------------
38 -- Local Subprograms --
39 -----------------------
41 procedure Get_Next_Code
45 EM
: WC_Encoding_Method
);
46 -- Scans next character starting at S(P) and returns its value in V. On
47 -- exit P is updated past the last character read. Raises Constraint_Error
48 -- if the string is not well formed. Raises Constraint_Error if the code
49 -- value is greater than 16#7FFF_FFFF#. On entry P <= S'Last.
55 procedure Get_Next_Code
59 EM
: WC_Encoding_Method
)
61 function In_Char
return Character;
62 -- Function to return a character, bumping P, raises Constraint_Error
63 -- if P > S'Last on entry.
65 function Get_UTF_32
is new Char_Sequence_To_UTF_32
(In_Char
);
66 -- Function to get next UFT_32 value
72 function In_Char
return Character is
75 raise Constraint_Error
with "badly formed wide character code";
82 -- Start of processing for Get_Next_Code
85 -- Check for wide character encoding
89 if S
(P
) = ASCII
.ESC
then
90 V
:= Get_UTF_32
(In_Char
, EM
);
94 when WCEM_Upper | WCEM_Shift_JIS | WCEM_EUC | WCEM_UTF8
=>
95 if S
(P
) >= Character'Val (16#
80#
) then
96 V
:= Get_UTF_32
(In_Char
, EM
);
100 when WCEM_Brackets
=>
103 and then S
(P
+ 1) = '"'
104 and then S
(P
+ 2) /= '"'
106 V
:= Get_UTF_32
(In_Char
, EM
);
111 -- If it is not a wide character code, just get it
113 V
:= Character'Pos (S
(P
));
117 ---------------------------
118 -- String_To_Wide_String --
119 ---------------------------
121 procedure String_To_Wide_String
125 EM
: System
.WCh_Con
.WC_Encoding_Method
)
131 pragma Assert
(S
'First = 1);
135 while SP
<= S
'Last loop
136 Get_Next_Code
(S
, SP
, V
, EM
);
139 raise Constraint_Error
with
140 "out of range value for wide character";
144 R
(L
) := Wide_Character'Val (V
);
146 end String_To_Wide_String
;
148 --------------------------------
149 -- String_To_Wide_Wide_String --
150 --------------------------------
152 procedure String_To_Wide_Wide_String
154 R
: out Wide_Wide_String
;
156 EM
: System
.WCh_Con
.WC_Encoding_Method
)
158 pragma Assert
(S
'First = 1);
166 while SP
<= S
'Last loop
167 Get_Next_Code
(S
, SP
, V
, EM
);
169 R
(L
) := Wide_Wide_Character
'Val (V
);
171 end String_To_Wide_Wide_String
;