Hosted by
|
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;
procedure To_Lower
(This : in out String) is
begin
for Index in This'Range loop
This(Index) := To_Lower(This(Index));
end loop;
end To_Lower;
procedure Replace_Char
(This : in out String;
A, B : in Character) is
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;
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;
|