1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- S Y S T E M . W W D _ W C H A R --
9 -- Copyright (C) 1992-2005, 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 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 with Interfaces
; use Interfaces
;
38 package body System
.Wwd_WChar
is
40 ------------------------------------
41 -- Wide_Wide_Width_Wide_Character --
42 ------------------------------------
44 -- This is the case where we are talking about the Wide_Wide_Image of
45 -- a Wide_Character, which is always the same character sequence as the
46 -- Wide_Image of the same Wide_Character.
48 function Wide_Wide_Width_Wide_Character
49 (Lo
, Hi
: Wide_Character) return Natural
52 return Wide_Width_Wide_Character
(Lo
, Hi
);
53 end Wide_Wide_Width_Wide_Character
;
55 ------------------------------------
56 -- Wide_Wide_Width_Wide_Wide_Char --
57 ------------------------------------
59 function Wide_Wide_Width_Wide_Wide_Char
60 (Lo
, Hi
: Wide_Wide_Character
) return Natural
63 LV
: constant Unsigned_32
:= Wide_Wide_Character
'Pos (Lo
);
64 HV
: constant Unsigned_32
:= Wide_Wide_Character
'Pos (Hi
);
67 -- Return zero if empty range
73 -- If any characters in normal character range, then use normal
74 -- Wide_Wide_Width attribute on this range to find out a starting point.
75 -- Otherwise start with zero.
79 System
.WWd_Char
.Wide_Wide_Width_Character
80 (Lo
=> Character'Val (LV
),
81 Hi
=> Character'Val (Unsigned_32
'Min (255, HV
)));
86 -- Increase to at least 4 if FFFE or FFFF present. These correspond
87 -- to the special language defined names FFFE/FFFF for these values.
89 if 16#FFFF#
in LV
.. HV
or else 16#FFFE#
in LV
.. HV
then
90 W
:= Natural'Max (W
, 4);
93 -- Increase to at least 3 if any wide characters, corresponding to
94 -- the normal ' character ' sequence. We know that the character fits.
97 W
:= Natural'Max (W
, 3);
101 end Wide_Wide_Width_Wide_Wide_Char
;
103 -------------------------------
104 -- Wide_Width_Wide_Character --
105 -------------------------------
107 function Wide_Width_Wide_Character
108 (Lo
, Hi
: Wide_Character) return Natural
111 LV
: constant Unsigned_32
:= Wide_Character'Pos (Lo
);
112 HV
: constant Unsigned_32
:= Wide_Character'Pos (Hi
);
115 -- Return zero if empty range
121 -- If any characters in normal character range, then use normal
122 -- Wide_Wide_Width attribute on this range to find out a starting point.
123 -- Otherwise start with zero.
127 System
.WWd_Char
.Wide_Width_Character
128 (Lo
=> Character'Val (LV
),
129 Hi
=> Character'Val (Unsigned_32
'Min (255, HV
)));
134 -- Increase to at least 4 if FFFE or FFFF present. These correspond
135 -- to the special language defined names FFFE/FFFF for these values.
137 if 16#FFFF#
in LV
.. HV
or else 16#FFFE#
in LV
.. HV
then
138 W
:= Natural'Max (W
, 4);
141 -- Increase to at least 3 if any wide characters, corresponding to
142 -- the normal 'character' sequence. We know that the character fits.
145 W
:= Natural'Max (W
, 3);
149 end Wide_Width_Wide_Character
;
151 ------------------------------------
152 -- Wide_Width_Wide_Wide_Character --
153 ------------------------------------
155 -- This is a nasty case, because we get into the business of representing
156 -- out of range wide wide characters as wide strings. Let's let image do
157 -- the work here. Too bad if this takes lots of time. It's silly anyway!
159 function Wide_Width_Wide_Wide_Character
160 (Lo
, Hi
: Wide_Wide_Character
) return Natural
166 for J
in Lo
.. Hi
loop
168 S
: constant Wide_String := Wide_Wide_Character
'Wide_Image (J
);
170 W
:= Natural'Max (W
, S
'Length);
175 end Wide_Width_Wide_Wide_Character
;
177 end System
.Wwd_WChar
;