-- $Date: 2004/02/02 08:48:33 $
-- $Revision: 1.1 $
-- $Author: jcrocholl $

package body String_Tools is

   function To_Lower
     (This : in Character)
     return Character
   is
      ASCII : constant Natural := Character'Pos(This);
   begin
      if This in 'A' .. 'Z'
        or else ASCII in 16#C0# .. 16#D6#
        or else ASCII in 16#D8# .. 16#DE#
      then
         return Character'Val(ASCII + 16#20#);
      else
         return This;
      end if;
   end To_Lower;

   -- Convert a string to lower case.
   procedure To_Lower
     (This : in out String) is -- Change this string.
   begin
      for Index in This'Range loop
         This(Index) := To_Lower(This(Index));
      end loop;
   end To_Lower;

   -- Replace characters in a string.
   procedure Replace_Char
     (This : in out String;   -- Change this string.
      A, B : in Character) is -- Replace A with B.
   begin
      for Index in This'Range loop
         if This(Index) = A then
            This(Index) := B;
         end if;
      end loop;
   end Replace_Char;

   function Last_Occurrence
     (This : in String;
      Char : in Character)
     return Natural is
   begin
      for Index in reverse This'Range loop
         if This(Index) = Char then
            return Index;
         end if;
      end loop;
      return This'First - 1;
   end Last_Occurrence;

   -- Extract a filename from a path, or an identifier from a fully
   -- qualified dotted notation. Return the suffix of the string that
   -- comes after the last occurrence of Char.
   function Suffix_After_Char
     (This : in String;
      Char : in Character)
     return String
   is
      Pos : Natural := Last_Occurrence(This, Char);
   begin
      return This(Pos + 1 .. This'Last);
   end Suffix_After_Char;

end String_Tools;