One approach might be to write a function that fills a fixed-length string with a dynamic-size input string, filling in the blanks:
procedure Pad_String(Str: in String; Dest: out String; Len: out Integer) is begin Len := Str'Last - Str'First + 1; Dest(Dest'First .. Dest'First + Len - 1) := Str(Str'First .. Str'First + Len - 1); Dest(Dest'First + Len .. Dest'Last) := Fill_String(Dest'Last - Len, ' '); end Pad_String;
Processing the Ada string allows you to pass any fixed-length buffer to Dest , and the attributes 'First and 'Last will be valid within the body of the procedure.
Then your code could become:
procedure F() is Msg : String(1..1024); Len : Integer; begin Open_Log(); Pad_String( FLS(" Field1", 12) & "|" & FLS(" Field2", 12) & "|" & FLS(" Field3", 16), Msg, Len); Log_To_File("# " & Msg(1 .. Len)); Log_To_File("# " & Fill_String(Len, '-')); end;
Greg hewgill
source share