* Merging revisions r46530 from trunk:

------------------------------------------------------------------------
    r46530 | michael | 2020-08-21 09:38:33 +0200 (Fri, 21 Aug 2020) | 1 line
    
    * Fix bug ID #0037605: Setting quotechar to NULL char disables quoting
    ------------------------------------------------------------------------

git-svn-id: branches/fixes_3_2@46640 -
This commit is contained in:
michael 2020-08-23 10:26:23 +00:00
parent 09a846ba71
commit c72cd8ef67

View File

@ -228,7 +228,6 @@ begin
BreakChars:=[#0,QuoteChar,Delimiter] BreakChars:=[#0,QuoteChar,Delimiter]
else else
BreakChars:=[#0..' ',QuoteChar,Delimiter]; BreakChars:=[#0..' ',QuoteChar,Delimiter];
// Check for break characters and quote if required. // Check for break characters and quote if required.
For i:=0 to count-1 do For i:=0 to count-1 do
begin begin
@ -242,7 +241,7 @@ begin
inc(p); inc(p);
DoQuote:=(p<>pchar(S)+length(S)); DoQuote:=(p<>pchar(S)+length(S));
end; end;
if DoQuote then if DoQuote and (QuoteChar<>#0) then
Result:=Result+QuoteString(S,QuoteChar) Result:=Result+QuoteString(S,QuoteChar)
else else
Result:=Result+S; Result:=Result+S;
@ -547,6 +546,27 @@ var
Add(StringReplace(Copy(AValue,i+1,j-i-1),aQuoteChar+aQuoteChar,aQuoteChar, [rfReplaceAll])); Add(StringReplace(Copy(AValue,i+1,j-i-1),aQuoteChar+aQuoteChar,aQuoteChar, [rfReplaceAll]));
end; end;
Function CheckQuoted : Boolean;
begin
Result:=(AValue[i]=aQuoteChar) and (aQuoteChar<>#0);
If Not Result then
exit;
// next string is quoted
j:=i+1;
while (j<=len) and
((AValue[j]<>aQuoteChar) or
((j+1<=len) and (AValue[j+1]=aQuoteChar))) do
begin
if (j<=len) and (AValue[j]=aQuoteChar) then
inc(j,2)
else
inc(j);
end;
AddQuoted;
i:=j+1;
end;
begin begin
BeginUpdate; BeginUpdate;
@ -565,28 +585,20 @@ begin
len:=length(AValue); len:=length(AValue);
If aStrictDelimiter then If aStrictDelimiter then
begin begin
while i<=Len do begin while i<=len do
begin
// skip delimiter // skip delimiter
if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then
inc(i); inc(i);
// read next string // read next string
if i<=len then begin if i>len then
if AValue[i]=aQuoteChar then begin
// next string is quoted
j:=i+1;
while (j<=len) and
((AValue[j]<>aQuoteChar) or
((j+1<=len) and (AValue[j+1]=aQuoteChar))) do
begin begin
if (j<=len) and (AValue[j]=aQuoteChar) then if aNotFirst then Add('');
inc(j,2) end
else else
inc(j); begin
end; If not CheckQuoted then
AddQuoted; begin
i:=j+1;
end else begin
// next string is not quoted; read until delimiter // next string is not quoted; read until delimiter
j:=i; j:=i;
while (j<=len) and while (j<=len) and
@ -594,53 +606,47 @@ begin
Add( Copy(AValue,i,j-i)); Add( Copy(AValue,i,j-i));
i:=j; i:=j;
end; end;
end else begin
if aNotFirst then Add('');
end; end;
aNotFirst:=true; aNotFirst:=true;
end; end;
end end
else else
begin begin
while i<=len do begin while i<=len do
begin
// skip delimiter // skip delimiter
if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then inc(i); if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then
inc(i);
// skip spaces // skip spaces
while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do inc(i); while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do inc(i);
// read next string // read next string
if i<=len then begin if i>len then
if AValue[i]=aQuoteChar then begin begin
if aNotFirst then Add('');
end
else
begin
// next string is quoted // next string is quoted
j:=i+1; if not CheckQuoted then
while (j<=len) and begin
( (AValue[j]<>aQuoteChar) or
( (j+1<=len) and (AValue[j+1]=aQuoteChar) ) ) do begin
if (j<=len) and (AValue[j]=aQuoteChar) then inc(j,2)
else inc(j);
end;
AddQuoted;
i:=j+1;
end else begin
// next string is not quoted; read until control character/space/delimiter // next string is not quoted; read until control character/space/delimiter
j:=i; j:=i;
while (j<=len) and while (j<=len) and
(Ord(AValue[j])>Ord(' ')) and (Ord(AValue[j])>Ord(' ')) and
(AValue[j]<>aDelimiter) do inc(j); (AValue[j]<>aDelimiter) do
inc(j);
Add( Copy(AValue,i,j-i)); Add( Copy(AValue,i,j-i));
i:=j; i:=j;
end; end;
end else begin
if aNotFirst then Add('');
end; end;
// skip spaces // skip spaces
while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do inc(i); while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do
inc(i);
aNotFirst:=true; aNotFirst:=true;
end; end; // While I<=Len
end; end; // If StrictDelimiter
finally finally
EndUpdate; EndUpdate;
end; end;