csvdocument: cleanup

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1628 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
vvzh
2011-05-10 13:34:31 +00:00
parent 5fdd6f03d4
commit 0dd62c13c1
2 changed files with 14 additions and 18 deletions

View File

@ -205,21 +205,20 @@ const
function ChangeLineEndings(const AString, ALineEnding: String): String; function ChangeLineEndings(const AString, ALineEnding: String): String;
var var
NewLength: Integer; I: Integer;
P, StartPos: Integer;
Src: PChar; Src: PChar;
Dest: PChar; Dest: PChar;
EndingStart: PChar; DestLength: Integer;
EndingLen: Integer; EndingLength: Integer;
EndPos: PChar; EndPos: PChar;
begin begin
if AString = '' then if AString = '' then
Exit(AString); Exit(AString);
EndingLen := Length(ALineEnding); EndingLength := Length(ALineEnding);
NewLength := Length(AString); DestLength := Length(AString);
Src := PChar(AString); Src := PChar(AString);
EndPos := Src + NewLength; EndPos := Src + DestLength;
while Src < EndPos do while Src < EndPos do
begin begin
if (Src^ = CR) then if (Src^ = CR) then
@ -228,28 +227,28 @@ begin
if (Src^ = LF) then if (Src^ = LF) then
begin begin
Inc(Src); Inc(Src);
Inc(NewLength, EndingLen - 2); Inc(DestLength, EndingLength - 2);
end else end else
Inc(NewLength, EndingLen - 1); Inc(DestLength, EndingLength - 1);
end else end else
begin begin
if (Src^ = LF) then if (Src^ = LF) then
Inc(NewLength, EndingLen - 1); Inc(DestLength, EndingLength - 1);
Inc(Src); Inc(Src);
end; end;
end; end;
SetLength(Result, NewLength); SetLength(Result, DestLength);
Src := PChar(AString); Src := PChar(AString);
Dest := PChar(Result); Dest := PChar(Result);
EndPos := Dest + NewLength; EndPos := Dest + DestLength;
while (Dest < EndPos) do while (Dest < EndPos) do
begin begin
if Src^ in LineEndingChars then if Src^ in LineEndingChars then
begin begin
for P := 1 to EndingLen do for I := 1 to EndingLength do
begin begin
Dest^ := ALineEnding[P]; Dest^ := ALineEnding[I];
Inc(Dest); Inc(Dest);
end; end;
if (Src^ = CR) and (Src[1] = LF) then if (Src^ = CR) and (Src[1] = LF) then

View File

@ -92,7 +92,6 @@ var
I: Integer; I: Integer;
TestFiles: TStringList; TestFiles: TStringList;
CurrentTestFile: String; CurrentTestFile: String;
InBuffer, OutBuffer: String;
begin begin
WriteLn('== Format: ', ASpec, ' =='); WriteLn('== Format: ', ASpec, ' ==');
TestFiles := TStringList.Create; TestFiles := TStringList.Create;
@ -109,14 +108,12 @@ begin
end; end;
procedure ExecPerformanceTest(ADocument: TCSVDocument; const AMinSizeKB: Integer); procedure ExecPerformanceTest(ADocument: TCSVDocument; const AMinSizeKB: Integer);
const
CsvLineEnding = #13#10;
var var
I, MaxRows: Integer; I, MaxRows: Integer;
Seq: String; Seq: String;
SeqLen: Integer; SeqLen: Integer;
RealSize: Integer; RealSize: Integer;
InBuffer, OutBuffer: String; InBuffer: String;
ParseTime: Int64; ParseTime: Int64;
BuildTime: Int64; BuildTime: Int64;
begin begin