gcc/
[official-gcc.git] / gcc / ada / s-wwdwch.adb
blob001680ef5bed57ca70ad1b854b55b6ea18e1b04c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME 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-2009, 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 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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 with Interfaces; use Interfaces;
34 with System.WWd_Char;
36 package body System.Wwd_WChar is
38 ------------------------------------
39 -- Wide_Wide_Width_Wide_Character --
40 ------------------------------------
42 -- This is the case where we are talking about the Wide_Wide_Image of
43 -- a Wide_Character, which is always the same character sequence as the
44 -- Wide_Image of the same Wide_Character.
46 function Wide_Wide_Width_Wide_Character
47 (Lo, Hi : Wide_Character) return Natural
49 begin
50 return Wide_Width_Wide_Character (Lo, Hi);
51 end Wide_Wide_Width_Wide_Character;
53 ------------------------------------
54 -- Wide_Wide_Width_Wide_Wide_Char --
55 ------------------------------------
57 function Wide_Wide_Width_Wide_Wide_Char
58 (Lo, Hi : Wide_Wide_Character) return Natural
60 LV : constant Unsigned_32 := Wide_Wide_Character'Pos (Lo);
61 HV : constant Unsigned_32 := Wide_Wide_Character'Pos (Hi);
63 begin
64 -- Return zero if empty range
66 if LV > HV then
67 return 0;
69 -- Return max value (12) for wide character (Hex_hhhhhhhh)
71 elsif HV > 255 then
72 return 12;
74 -- If any characters in normal character range, then use normal
75 -- Wide_Wide_Width attribute on this range to find out a starting point.
76 -- Otherwise start with zero.
78 else
79 return
80 System.WWd_Char.Wide_Wide_Width_Character
81 (Lo => Character'Val (LV),
82 Hi => Character'Val (Unsigned_32'Min (255, HV)));
83 end if;
84 end Wide_Wide_Width_Wide_Wide_Char;
86 -------------------------------
87 -- Wide_Width_Wide_Character --
88 -------------------------------
90 function Wide_Width_Wide_Character
91 (Lo, Hi : Wide_Character) return Natural
93 LV : constant Unsigned_32 := Wide_Character'Pos (Lo);
94 HV : constant Unsigned_32 := Wide_Character'Pos (Hi);
96 begin
97 -- Return zero if empty range
99 if LV > HV then
100 return 0;
102 -- Return max value (12) for wide character (Hex_hhhhhhhh)
104 elsif HV > 255 then
105 return 12;
107 -- If any characters in normal character range, then use normal
108 -- Wide_Wide_Width attribute on this range to find out a starting point.
109 -- Otherwise start with zero.
111 else
112 return
113 System.WWd_Char.Wide_Width_Character
114 (Lo => Character'Val (LV),
115 Hi => Character'Val (Unsigned_32'Min (255, HV)));
116 end if;
117 end Wide_Width_Wide_Character;
119 ------------------------------------
120 -- Wide_Width_Wide_Wide_Character --
121 ------------------------------------
123 function Wide_Width_Wide_Wide_Character
124 (Lo, Hi : Wide_Wide_Character) return Natural
126 begin
127 return Wide_Wide_Width_Wide_Wide_Char (Lo, Hi);
128 end Wide_Width_Wide_Wide_Character;
130 end System.Wwd_WChar;