(*--------------------------------------------------------------------------*)
(*               LTrim --- LTrim leading blanks from a string               *)
(*--------------------------------------------------------------------------*)

FUNCTION LTrim( S : AnyStr ) : AnyStr;

(*--------------------------------------------------------------------------*)
(*                                                                          *)
(*     Function:   LTrim                                                    *)
(*                                                                          *)
(*     Purpose:    Trims leading blanks from a string                       *)
(*                                                                          *)
(*     Calling sequence:                                                    *)
(*                                                                          *)
(*         LTrimmed_S := TRIM( S );                                         *)
(*                                                                          *)
(*            S           --- the string to be trimmed                      *)
(*            LTrimmed_S  --- the trimmed version of S                      *)
(*                                                                          *)
(*     Calls:  None                                                         *)
(*                                                                          *)
(*     Remarks:                                                             *)
(*                                                                          *)
(*        Note that the original string itself is left untrimmed.           *)
(*                                                                          *)
(*--------------------------------------------------------------------------*)

VAR
   I:       INTEGER;
   Trimmed: BOOLEAN;
   L:       INTEGER;

BEGIN (* LTrim *)

   LTrim := '';

   IF LENGTH( S ) > 0 THEN
      BEGIN

         I       := 0;
         L       := LENGTH( S );
         Trimmed := FALSE;

         REPEAT

            I := I + 1;
            IF ( I <= L ) THEN
               Trimmed := S[I] <> ' '
            ELSE
               Trimmed := TRUE;

         UNTIL Trimmed;

         IF ( ( L - I + 1 ) > 0 ) THEN
            LTrim := COPY( S, I, L - I + 1 );

      END;

END   (* LTrim *);
