--------------------------------------------------------------------------- -- Title : TypeAK -- Version : 1.0 -- Author : David Wallace Croft -- Compiler : Ada -- Copyright : 1994 David Wallace Croft. All rights reserved. -- Description : Data type manipulation --------------------------------------------------------------------------- package body TypeAK is --------------------------------------------------------------------------- --------------------------------------------------------------------------- function Filter ( In_Str: in string; Filter_Str: in string ) return string is --------------------------------------------------------------------------- In_Filter_Str : boolean; Position : integer := In_Str'first; Temp : string ( In_Str'range ); begin for index in In_Str'range loop In_Filter_Str := false; for index2 in Filter_Str'range loop if In_Str ( index ) = Filter_Str ( index2 ) then In_Filter_Str := true; exit; end if; end loop; if not In_Filter_Str then Temp ( Position ) := In_Str ( index ); Position := Position + 1; end if; end loop; for index in Position .. In_Str'last loop Temp ( index ) := ASCII.NUL; end loop; return Temp; end Filter; procedure Parse ( String_Array : out String_Array_Type; Str_In : in string; Comments : in string := Comments_Default; Delimiters : in string := Delimiters_Default; White_Space : in string := White_Space_Default ) is --------------------------------------------------------------------------- -- Title : Parse -- Version : 1.0 -- Author : David Wallace Croft -- Compiler : Ada -- Copyright : 1993 David Wallace Croft. All rights reserved. -- Description : -- Breaks a string into several strings as separated by the -- delimiters and white space. Ignores leading white space but not a -- leading delimiters. Ignores characters after the comment character. -- Example: " , Hello, you there! How are you?" -- ==> ( ( ASCII.Nul, ASCII.Nul, ASCII.Nul, ASCII.Nul ), -- ( 'H' , 'e' , 'l' , 'l' ), -- ( 'y' , 'o' , 'o' , ASCII.Nul ), -- ( 't' , 'h' , 'e' , 'r' ) ) --------------------------------------------------------------------------- Char : positive range Str_In'range := 1; begin -- initialize output to null String_Array := ( others => ( others => ASCII.Nul ) ); for Str_Index in String_Array'range loop -- strip leading white space for index in Char..Str_In'last loop exit when not Subset ( Str_In ( index ), White_Space ); if Char = Str_In'last then return; end if; Char := Char + 1; end loop; -- read word until delimiter, comment, or white space reached for Char_Index in String_Array ( 1 )'range loop if Subset ( Str_In ( Char ), Comments ) then return; end if; if Subset ( Str_In ( Char ), Delimiters ) then -- Skip past the delimiter if Char = Str_In'last then return; end if; Char := Char + 1; exit; end if; exit when Subset ( Str_In ( Char ), White_Space ); String_Array ( Str_Index ) ( Char_Index ) := Str_In ( Char ); if Char = Str_In'last then return; end if; Char := Char + 1; end loop; -- skip character(s) to get past remaining characters in a word -- Ex.: (index Char = *) long*word ==> longword* loop if Subset ( Str_In ( Char ), Comments ) then return; end if; exit when Subset ( Str_In ( Char ), Delimiters ); exit when Subset ( Str_In ( Char ), White_Space ); if Char = Str_In'last then return; end if; Char := Char + 1; end loop; end loop; end Parse; function Subset ( Char : in character; Str : in string ) return boolean is --------------------------------------------------------------------------- --------------------------------------------------------------------------- -- Title : Subset -- Version : 1.0 -- Author : David Wallace Croft -- Compiler : Ada -- Copyright : 1993 David Wallace Croft. All rights reserved. -- Description : -- Returns true if the character exists anywhere in the string. --------------------------------------------------------------------------- --------------------------------------------------------------------------- begin for index in Str'range loop if Char = Str ( index ) then return true; end if; end loop; return false; end Subset; function Trim ( Str_In : in string ) return string is --------------------------------------------------------------------------- -- Title : Trim -- Version : 1.0 -- Author : David Wallace Croft, CompuServe [76600,102] -- Compiler : Ada -- Unit Type : function -- Copyright : 1993 David Wallace Croft. All rights reserved. -- Description : Returns a string without trailing white space. --------------------------------------------------------------------------- Length: natural := Str_In'last; begin for index in reverse Str_In'range loop exit when not Subset ( Str_In ( index ), White_Space_Default ); Length := index - 1; end loop; return Str_In ( 1..Length ); end Trim; --------------------------------------------------------------------------- --------------------------------------------------------------------------- end TypeAK;