Changeset 5 for trunk


Ignore:
Timestamp:
Jul 31, 2015, 11:43:28 AM (9 years ago)
Author:
chronos
Message:
  • Modified: Detect all three line ending types at the same time.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/linetime.lpr

    r4 r5  
    2828    TermString: string;
    2929    TermStringIndex: Integer;
     30    function FindLineEnding(Buffer: string; var LineEndingLength: Integer): Integer;
    3031    procedure WriteRaw(Text: string);
    3132    procedure WriteLog(Text: string);
     
    102103end;
    103104
     105function TMyApplication.FindLineEnding(Buffer: string; var LineEndingLength: Integer): Integer;
     106const
     107  LineEnding1 = #13#10;
     108  LineEnding2 = #10;
     109  LineEnding3 = #13;
     110var
     111  P: Integer;
     112begin
     113  Result := 0;
     114  LineEndingLength := 0;
     115
     116  P := Pos(LineEnding1, Buffer);
     117  if (P > 0) and (((Result > 0) and (P < Result)) or (Result = 0)) then begin
     118    Result := P;
     119    LineEndingLength := Length(LineEnding1);
     120  end;
     121  P := Pos(LineEnding2, Buffer);
     122  if (P > 0) and (((Result > 0) and (P < Result)) or (Result = 0)) then begin
     123    Result := P;
     124    LineEndingLength := Length(LineEnding2);
     125  end;
     126  P := Pos(LineEnding3, Buffer);
     127  if (P > 0) and (((Result > 0) and (P < Result)) or (Result = 0)) then begin
     128    Result := P;
     129    LineEndingLength := Length(LineEnding3);
     130  end;
     131end;
     132
    104133procedure TMyApplication.WriteRaw(Text: string);
    105134begin
     
    152181  I: Integer;
    153182  Part: string;
     183  LineEndingLength: Integer;
    154184begin
    155185  repeat
    156     P := Pos(LineEnding, Buffer);
     186    P := FindLineEnding(Buffer, LineEndingLength);
    157187    if P > 0 then begin
    158188      Part := Copy(Buffer, 1, P - 1);
     
    160190        Part := StringReplace(Part, '"', '""', [rfReplaceAll]);
    161191      PrintOutput(Part);
    162       Delete(Buffer, 1, P + Length(LineEnding) - 1);
     192      Delete(Buffer, 1, P + LineEndingLength - 1);
    163193      NewLine := True;
    164194      ShowTime := True;
Note: See TracChangeset for help on using the changeset viewer.