File : s-widwch.adb


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT RUN-TIME COMPONENTS                         --
   4 --                                                                          --
   5 --                     S Y S T E M . W I 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 package body System.Wid_WChar is
  33 
  34    --------------------------
  35    -- Width_Wide_Character --
  36    --------------------------
  37 
  38    function Width_Wide_Character
  39      (Lo, Hi : Wide_Character) return Natural
  40    is
  41       W : Natural;
  42       P : Natural;
  43 
  44    begin
  45       W := 0;
  46       for C in Lo .. Hi loop
  47          P := Wide_Character'Pos (C);
  48 
  49          --  Here if we find a character in wide character range
  50          --  Width is max value (12) for Hex_hhhhhhhh
  51 
  52          if P > 16#FF# then
  53             return 12;
  54 
  55             --  If we are in character range then use length of character image
  56 
  57          else
  58             declare
  59                S : constant String := Character'Image (Character'Val (P));
  60             begin
  61                W := Natural'Max (W, S'Length);
  62             end;
  63          end if;
  64       end loop;
  65 
  66       return W;
  67    end Width_Wide_Character;
  68 
  69    -------------------------------
  70    -- Width_Wide_Wide_Character --
  71    -------------------------------
  72 
  73    function Width_Wide_Wide_Character
  74      (Lo, Hi : Wide_Wide_Character) return Natural
  75    is
  76       W : Natural;
  77       P : Natural;
  78 
  79    begin
  80       W := 0;
  81       for C in Lo .. Hi loop
  82          P := Wide_Wide_Character'Pos (C);
  83 
  84          --  Here if we find a character in wide wide character range.
  85          --  Width is max value (12) for Hex_hhhhhhhh
  86 
  87          if P > 16#FF# then
  88             W := 12;
  89 
  90          --  If we are in character range then use length of character image
  91 
  92          else
  93             declare
  94                S : constant String := Character'Image (Character'Val (P));
  95             begin
  96                W := Natural'Max (W, S'Length);
  97             end;
  98          end if;
  99       end loop;
 100 
 101       return W;
 102    end Width_Wide_Wide_Character;
 103 
 104 end System.Wid_WChar;