---------------------------------------------------------------
--                                                           
--  RAPID - Rapid Ada Portable Interface Designer
--                                                           
--  MCC.TEXT_ENTRY_TYPES 
--  Description : specifies types for auto-fill of Text_Entry
--                       
--  By: Martin Carlisle
--                                         
-- RAPID is free software; you can redistribute it and/or 
-- modify it without restriction.  However, we ask that you
-- please retain the original author information, and clearly  
-- indicate if it has been modified.
--
-- RAPID is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
--
---------------------------------------------------------------
with ada.float_text_io;
with ada.strings.fixed;
package body mcc.text_entry_types is

   -----------
   -- Image --
   -----------

   function Image (data : in Standard.Integer) return String is
      x : String := standard.integer'image(data);
   begin
      if x(x'first) = ' ' then
         return x(x'first+1..x'last);
      else
         return x;
      end if;
   end Image;

   -----------
   -- Image --
   -----------

   function Image (data : in Float; base : in float_types) return String is
   begin
      case base is
         -- return just the image removing a leading space.
         when float_e =>
            declare 
               x : String := Float'Image(data);
            begin
               if x(x'first) = ' ' then
                  return x(x'first+1..x'last);
               else
                  return x;
               end if;
            end;
         when others =>
            -- print to a string, then return the relevant (non-blank)
            -- portion
            declare 
               x : String(1..80);
               first : natural;
            begin
               Ada.Float_Text_IO.Put(
                  To   => X,
                  Item => Data,
                  Aft  => Base_Type'Pos(base)-Base_Type'Pos(Float_1)+1,
                  Exp  => 0);
               first := ada.strings.fixed.index_non_blank(x);
               return x(first..x'last);
            end;
      end case;
   end Image;

end mcc.text_entry_types;

