!+ ! Tools Group ! Space Telescope Science Institute ! 3700 San Martin Drive ! Baltimore, MD 21218 ! ! NAME ! SCAN_STRING_UTILS ! ! DESCRIPTION ! File contains a set of SCAN string utilities that can ! make life easy ... ! ! RETURN VALUE ! ! HISTORY ! 11/88 Bauer Created for use in MMSGEN !- MODULE SCAN_STRING_UTILS; ! ! Substitutes a string for another ! PROCEDURE substitute_string ( change_this : STRING, to_that : STRING, in_this_string : STRING ); DECLARE temp : STRING; DECLARE s1, len1, len2 : INTEGER; s1 = INDEX (in_this_string, change_this); IF s1 = 0 THEN RETURN; END IF; len1 = LENGTH(in_this_string); len2 = LENGTH(change_this); temp = in_this_string[1..s1-1]; IF len1-len2+1 = s1 THEN temp = temp & to_that; ELSE temp = temp & to_that & in_this_string[(s1+len2)..]; END IF; in_this_string = temp; END PROCEDURE; ! ! Substitutes all occurrences of a string for another ! PROCEDURE substitute_all_strings ( change_this : STRING, to_that : STRING, in_this_string : STRING ); DECLARE temp1, temp2 : STRING; DECLARE s1, len1, len2 : INTEGER; temp1 = in_this_string; temp2 = in_this_string; CALL substitute_string (change_this, to_that, temp1); WHILE (temp1 <> temp2); temp2 = temp1; CALL substitute_string (change_this, to_that, temp1); END WHILE; in_this_string = temp1; END PROCEDURE; END MODULE;