--  Implementation of the palindrome package

with Ada.Characters.Handling; use Ada.Characters.Handling;

package body palspkg is

   function rev(s: String) return String is
      ans: String(s'range);
      start_right: constant Natural := s'first + s'last;
   begin
      for i in s'range loop
         ans(i) := s(start_right - i);
      end loop;
      return ans;
   end rev;

   function is_pal(s: String) return Boolean is
      ans: Boolean;
   begin
      if s'length < min_length then
         ans := false;
      else
         if case_sensitive then
            ans := s = rev(s);
         else
            ans := to_upper(s) = to_upper(rev(s));
         end if;
      end if;
      return ans;
   end is_pal;

   function min_pal_length return Natural is 
      (min_length);

   procedure make_pal(orig: String; new_pal: out String) is
   begin
      new_pal := orig & rev(orig);
   end make_pal;

end palspkg;