File : s-wwdwch.adb


   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 --                                                                          --
  19 --                                                                          --
  20 --                                                                          --
  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 ------------------------------------------------------------------------------
  31 
  32 with Interfaces; use Interfaces;
  33 
  34 with System.WWd_Char;
  35 
  36 package body System.Wwd_WChar is
  37 
  38    ------------------------------------
  39    -- Wide_Wide_Width_Wide_Character --
  40    ------------------------------------
  41 
  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.
  45 
  46    function Wide_Wide_Width_Wide_Character
  47      (Lo, Hi : Wide_Character) return Natural
  48    is
  49    begin
  50       return Wide_Width_Wide_Character (Lo, Hi);
  51    end Wide_Wide_Width_Wide_Character;
  52 
  53    ------------------------------------
  54    -- Wide_Wide_Width_Wide_Wide_Char --
  55    ------------------------------------
  56 
  57    function Wide_Wide_Width_Wide_Wide_Char
  58      (Lo, Hi : Wide_Wide_Character) return Natural
  59    is
  60       LV : constant Unsigned_32 := Wide_Wide_Character'Pos (Lo);
  61       HV : constant Unsigned_32 := Wide_Wide_Character'Pos (Hi);
  62 
  63    begin
  64       --  Return zero if empty range
  65 
  66       if LV > HV then
  67          return 0;
  68 
  69       --  Return max value (12) for wide character (Hex_hhhhhhhh)
  70 
  71       elsif HV > 255 then
  72          return 12;
  73 
  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.
  77 
  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;
  85 
  86    -------------------------------
  87    -- Wide_Width_Wide_Character --
  88    -------------------------------
  89 
  90    function Wide_Width_Wide_Character
  91      (Lo, Hi : Wide_Character) return Natural
  92    is
  93       LV : constant Unsigned_32 := Wide_Character'Pos (Lo);
  94       HV : constant Unsigned_32 := Wide_Character'Pos (Hi);
  95 
  96    begin
  97       --  Return zero if empty range
  98 
  99       if LV > HV then
 100          return 0;
 101 
 102       --  Return max value (12) for wide character (Hex_hhhhhhhh)
 103 
 104       elsif HV > 255 then
 105          return 12;
 106 
 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.
 110 
 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;
 118 
 119    ------------------------------------
 120    -- Wide_Width_Wide_Wide_Character --
 121    ------------------------------------
 122 
 123    function Wide_Width_Wide_Wide_Character
 124      (Lo, Hi : Wide_Wide_Character) return Natural
 125    is
 126    begin
 127       return Wide_Wide_Width_Wide_Wide_Char (Lo, Hi);
 128    end Wide_Width_Wide_Wide_Character;
 129 
 130 end System.Wwd_WChar;