Mark ChangeLog
[official-gcc.git] / gcc / ada / s-wwdwch.adb
blobac3d1e9cc45b0273d929fe766fda0832235650ef
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUNTIME COMPONENTS --
4 -- --
5 -- S Y S T E M . W W D _ W C H A R --
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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 Interfaces; use Interfaces;
36 with System.WWd_Char;
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
51 begin
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
62 W : Natural := 0;
63 LV : constant Unsigned_32 := Wide_Wide_Character'Pos (Lo);
64 HV : constant Unsigned_32 := Wide_Wide_Character'Pos (Hi);
66 begin
67 -- Return zero if empty range
69 if LV > HV then
70 return 0;
71 end if;
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.
77 if LV <= 255 then
78 W :=
79 System.WWd_Char.Wide_Wide_Width_Character
80 (Lo => Character'Val (LV),
81 Hi => Character'Val (Unsigned_32'Min (255, HV)));
82 else
83 W := 0;
84 end if;
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);
91 end if;
93 -- Increase to at least 3 if any wide characters, corresponding to
94 -- the normal ' character ' sequence. We know that the character fits.
96 if HV > 255 then
97 W := Natural'Max (W, 3);
98 end if;
100 return W;
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
110 W : Natural := 0;
111 LV : constant Unsigned_32 := Wide_Character'Pos (Lo);
112 HV : constant Unsigned_32 := Wide_Character'Pos (Hi);
114 begin
115 -- Return zero if empty range
117 if LV > HV then
118 return 0;
119 end if;
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.
125 if LV <= 255 then
126 W :=
127 System.WWd_Char.Wide_Width_Character
128 (Lo => Character'Val (LV),
129 Hi => Character'Val (Unsigned_32'Min (255, HV)));
130 else
131 W := 0;
132 end if;
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);
139 end if;
141 -- Increase to at least 3 if any wide characters, corresponding to
142 -- the normal 'character' sequence. We know that the character fits.
144 if HV > 255 then
145 W := Natural'Max (W, 3);
146 end if;
148 return W;
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
162 W : Natural;
164 begin
165 W := 0;
166 for J in Lo .. Hi loop
167 declare
168 S : constant Wide_String := Wide_Wide_Character'Wide_Image (J);
169 begin
170 W := Natural'Max (W, S'Length);
171 end;
172 end loop;
174 return W;
175 end Wide_Width_Wide_Wide_Character;
177 end System.Wwd_WChar;