2.1.5. Character Array Manipulation

Version I.5, September 1978

page131 Caution

These intrinsics are all byte oriented. Use them with care. Read the descriptions carefully before trying them out as no range checking of any sort is performed on the parameters passed to these routines. The programmer should know exactly what he is doing before he does it since the system does not protect itself from these operations. There may lurk some machine dependencies in the implementations of these, beware of byte / word and byte-sex problems.

2.1.5.1. Scan

FUNCTION SCAN(LENGTH, partial-expression, ARRAY): INTEGER;

This function returns the number of characters from the starting position to where it terminated, i.e. the number of characters scanned. It terminates on either matching the specified LENGTH or satisfying the partial-expression. The ARRAY should be a PACKED ARRAY OF CHAR and may be subscripted to denote the starting point. If the expression is satisfied on the character at which ARRAY is pointed, the value returned will be zero. If the length passed was negative, the number returned will also be negative, and the function will have scanned backward. The PARTIAL EXPRESSION must be of the form:

“<>” or “=” followed by <character-expression>

Examples: Using the array:

DEM := '.....THE TERAK IS A MEMBER CF THE PTERODACTYL FAMILY.';

SCAN(-26, = ':', DEM[30]);
    will return -26
SCAN(100, <> '.', DEM);
    will return 5
SCAN(15, = ' ', DEM[O]);
    will return 8

2.1.5.2. Moveleft

PROCEDURE MOVELEFT(SOURCE: array, DESTINATION: array, LENGTH: INTEGER);

2.1.5.3. Moveright

PROCEDURE MOVERIGHT(SOURCE: array, DESTINATION: array, LENGTH: INTEGER);

page132 These functions do mass moves of bytes for the length specified. MOVELEFT starts from the left end of the specified source and moves bytes to the Left end of the destination. MOVERIGHT starts from the right ends of both arrays and also moves byte by byte.

Some implementations of these intrinsics may do optimization of such a move for the specific hardware involved.

In short: MOVELEFT starts at the left end of both arrays and copies bytes traveling right. MOVERIGHT starts at the right end of both arrays and copies bytes traveling left. The reason for having both of these is if you are working in a single array and the order in which characters are moved is critical. The following chart is an attempt to show what happens if you use the procedure which moves in the wrong direction for your purposes.

VAR ARAY: PACKED ARRAY [1..30] OF CHAR;

     (*123456789012345678901234567890*)
ARAY: |THIS IS THE TEXT IN THIS ARRAY|
        MOVERIGHT(ARAY[10], ARAY[1], 10);
ARAY: |HE TEXT INE TEXT IN THIS ARRAY|
        MOVELEFT(ARAY[1], ARAY[3], 10)
ARAY: |HEHEHEHEHEHETEXT IN THIS ARRAY|
        MOVELEFT(ARAY[23], ARAY[2], 8);
ARAY: |HIS ARRAYENETEXT IN THIS ARRAY|

2.1.5.4. Fillchar

PROCEDURE FILLCHAR(DESTINATION: array, LENGTH: array, CHARACTER: CHAR);

This procedure takes a (subscripted) PACKED ARRAY OF CHAR and fills it with the number (LENGTH) of CHARACTERS specified. This can be done by:

A[0] := <character-expression>
MOVELEFT(A[0], A[1], LENGTH - 1);

but FILLCHAR is twice as fast, as no memory reference is needed for a source.

See the note about move optimization in the section on MOVELEFT.

The notes about MOVELEFT also apply to FILLCHAR.

2.1.5.5. See Also

The intrinsic SIZEOF (Section 2.1.6.1) is meant for use with these intrinsics; as it is convenient not to have to figure out or remember the number of bytes in a particular data structure. (Which may change at the programmers whim.)
This page last regenerated Sun Jul 25 01:09:11 2010.