-- $Date: 2004/03/01 01:28:51 $
-- $Revision: 1.5 $
-- $Author: jcrocholl $

with Ada.Text_IO; use Ada.Text_IO;
with String_Tools; use String_Tools;

package body Enum_Strings is

   -- Convert an enumeration type image into an XML entity name.
   function To_XML
     (This : in String-- Convert this enumeration type image.
     return String      -- The XML formatted string value.
   is
      Result : String := This;
   begin
      if Result'Length /= 1 then
         To_Lower(Result);
      end if;

      for Index in Result'Range loop
         if Result(Index) = '_' then
            Result(Index) := '-';
         end if;
      end loop;

      if Result'Length > 2
        and then Result(Result'First .. Result'First + 1) = "n-"
      then
         -- Put_Line(Current_Error, "omitting n-: " & Result);
         return Result(Result'First + 2 .. Result'Last);
      else
         return Result;
      end if;
   end To_XML;

   -- Translate an XML entity name into the corresponding enumeration
   -- value.
   function To_Enum
     (Name : in String)
     return Enum is
   begin
      for Index in Enum'Range loop
         if Name = To_XML(Index'Img) then
            return Index;
         end if;
      end loop;
      Put_Line(Current_Error, "unknown: " & Name);
      raise Expectation;
   end To_Enum;

   function To_Boolean
     (This : in String)
     return Boolean is
   begin
      return This = "yes";
   end To_Boolean;

end Enum_Strings;