home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Plus SuperCD 45
/
SuperCD45.iso
/
talleres
/
prog_alternat
/
StringUtils
/
stringutils.mod
next >
Wrap
Text File
|
1999-10-31
|
3KB
|
86 lines
MODULE StringUtils;
IMPORT In,Out,st := Strings;
TYPE
STRING50 = ARRAY 50 OF CHAR;
someP* = POINTER TO someR;
someR = RECORD
datatype : STRING50;
END;
intP = POINTER TO intR;
intR = RECORD(someR)
i* : INTEGER;
END;
chP* = POINTER TO chR;
chR = RECORD(someR);
c* : CHAR;
END;
strP* = POINTER TO strR;
strR = RECORD(someR);
s* : STRING50;
END;
arr10T* = ARRAY 10 OF someP;
arrT* = ARRAY OF someP;
PROCEDURE ProcessArray( VAR s : st.StringT; arr : arrT );
VAR
pos, ActualLen, i, SearchStart : LONGINT;
msg, ints : STRING50;
BEGIN
(* Display the total length of the array, arr *)
(* This is for testing purposes only *)
Out.Ln;
Out.String( "Array Length = " );
Out.Int( LEN(arr), 0 );
(* Now find the number, ActualLen, of the array-slots that contain data (i.e. that aren't NIL ) *)
ActualLen := 0;
WHILE arr[ActualLen] # NIL DO INC(ActualLen); END;
Out.Ln;
Out.String( "Actual Array Length = " );
Out.Int( ActualLen, 0 );
Out.Ln;
(* ===== Start of string formatting code ===== *)
SearchStart := 0; (* initially search for % from index 0 in string *)
FOR i := 0 TO ActualLen-1 DO (* FOR each object in the array... *)
pos := st.PosChar('%', s, SearchStart ); (* ...find the pos of the % char... *)
IF arr[i] IS chP THEN (* IF array item is chP... *)
(*--- some debug output ---*)
Out.String( "It's a char! - " );
Out.Char( arr[i](chP)^.c ); (* ^ here is optional *)
Out.Ln;
(*-------------------------*)
s[pos-1] := arr[i](chP)^.c; (* ...insert char, c, at pos of % in string *)
ELSIF arr[i] IS intP THEN (* ELSE IF array item is intP... *)
(*--- some debug output ---*)
Out.String( "It's an integer! - " );
Out.Int( arr[i](intP)^.i, 2 );
Out.Ln;
(*-------------------------*)
st.Delete(s, pos, 1); (* ...convert i to string and insert it at pos of % *)
st.Str(arr[i](intP)^.i, ints );
st.Insert(ints, s, pos );
ELSIF arr[i] IS strP THEN (* ELSE IF array item is strP... *)
(*--- some debug output ---*)
Out.String( "It's a string! - " );
Out.String( arr[i](strP)^.s );
Out.Ln;
(*-------------------------*)
st.Delete(s, pos, 1); (* ...insert it at pos of % in the string *)
st.Insert(arr[i](strP)^.s, s, pos );
ELSE (* ELSE array item is something else, so say so! *)
Out.String( "It's summat else!" );
END;
SearchStart := pos + 1; (* reset search index when looking for % next time *)
END; (* FOR 0 TO... *)
END ProcessArray;
BEGIN
END StringUtils.