MODULE InfoTrans;

	

	IMPORT
		Strings;

	CONST
		substitute = "-";	(* substitute character *)

	PROCEDURE TransChar1* (ch: CHAR): CHAR;
		VAR res: CHAR;
	BEGIN
		CASE ch OF
		 	0000X .. 001FX: res := substitute	(* ASCII control character *)
		|	'\': res := substitute	(* back slash *)
		|	'/': res := substitute	(* forward slash *)
		|	':': res := substitute	(* colon *)
		|	'*': res := substitute	(* asterisk *)
		|	'?': res := substitute	(* question mark *)
		|	'"': res := substitute	(* double quotes *)
		|	'<': res := substitute	(* left angle bracket *)
		|	'>': res := substitute	(* right angle bracket *)
		|	'|': res := substitute	(* pipe *)
		|	'~': res := substitute	(* tilde *)
		|	007FX: res := substitute
		|	0080X .. 009FX: res := substitute
		|	00FFX: res := substitute
		ELSE
			res := ch
		END;
		RETURN res
	END TransChar1;

	PROCEDURE TransChar2* (ch: CHAR): CHAR;
		VAR res: CHAR;
	BEGIN
		CASE ch OF
		 	' ': res := substitute	(* blank spaces *)
		|	'.': res := substitute	(* period *)
		|	';': res := substitute	(* semicolon *)
		|	',': res := substitute	(* comma *)
		|	'#': res := substitute	(* pound *)
		|	'%': res := substitute	(* percent *)
		|	'&': res := substitute	(* ampersand *)
		|	'{': res := substitute	(* left curly bracket *)
		|	'}': res := substitute	(* right curly bracket *)
		|	'$': res := substitute	(* dollar sign *)
		|	'!': res := substitute	(* exclamation point *)
		|	"'": res := substitute	(* single quotes *)
		|	'@': res := substitute	(* at sign *)
		|	'+': res := substitute	(* plus sign *)
		|	'`': res := substitute	(* backtick *)
		|	'=': res := substitute	(* equal sign *)
		|	'(': res := substitute	(* left bracket *)
		|	')': res := substitute	(* right bracket *)
		|	'[': res := substitute	(* left squared bracket *)
		|	']': res := substitute	(* right squared bracket *)
		ELSE
			res := ch
		END;
		RETURN res
	END TransChar2;

	PROCEDURE TrimChar* (VAR source: ARRAY OF CHAR; ch: CHAR);
		VAR a, b, i, k, n: INTEGER;
	BEGIN
		(* delete first, last and double char *)
		a := 0; b := LEN(source$) - 1;
		WHILE (a <= b) & (source[a] = ch) DO a := a + 1 END; (* first char *)
		WHILE (a <= b) & (source[b] = ch) DO b := b - 1 END; (* last char *)
		Strings.Extract(source, a, b - a + 1, source); (* Substr - delete first & last char *)
		n := LEN(source$); (* delete double char - e.g. maximal 1 Blank zwischen den Wrter *)
		FOR i := n - 1 TO 0 BY - 1 DO
			IF (source[i] = ch) & (source[i + 1] = ch) THEN
				FOR k := i TO n - 1 DO
					source[k] := source[k + 1]
				END;
			END;
		END;
	END TrimChar;

	PROCEDURE Trim* (VAR source: ARRAY OF CHAR);
	BEGIN
		TrimChar(source, ' ');	(* trim spaces *)
		TrimChar(source, substitute);	(* trim substitute character *)
		(*
		TrimChar(source, '-');	(* trim hyphen *)
		TrimChar(source, '_');	(* trim underscores *)
		TrimChar(source, '.');	(* trim period *)
		*)
	END Trim;

	PROCEDURE BuildNewName (IN old: ARRAY OF CHAR; OUT new: ARRAY OF CHAR);
		VAR i, j: INTEGER;
	BEGIN
		j := 0;
		FOR i := 0 TO LEN(old$) DO
			CASE old[i] OF
				' ': new[j] := '_';
				| '': new[j] := 'A'; INC(j); new[j] := 'E';
				| '': new[j] := 'a'; INC(j); new[j] := 'e';
				| '': new[j] := 'O'; INC(j); new[j] := 'E';
				| '': new[j] := 'o'; INC(j); new[j] := 'e';
				| '': new[j] := 'U'; INC(j); new[j] := 'E';
				| '': new[j] := 'u'; INC(j); new[j] := 'e';
				| '': new[j] := 's'; INC(j); new[j] := 's';
				ELSE new[j] := old[i];
			END;
			INC(j);
		END;
		new[j] := 0X;
	END BuildNewName;

END InfoTrans.
