Hosted by
|
with Ada.Text_IO; use Ada.Text_IO;
with String_Tools; use String_Tools;
package body Enum_Strings is
function To_XML
(This : in String)
return String
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
return Result(Result'First + 2 .. Result'Last);
else
return Result;
end if;
end To_XML;
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;
|