mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 20:29:14 +02:00
* 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:
parent
09a846ba71
commit
c72cd8ef67
@ -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,82 +585,68 @@ begin
|
|||||||
len:=length(AValue);
|
len:=length(AValue);
|
||||||
If aStrictDelimiter then
|
If aStrictDelimiter then
|
||||||
begin
|
begin
|
||||||
while i<=Len do begin
|
while i<=len do
|
||||||
// skip delimiter
|
begin
|
||||||
if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then
|
// skip delimiter
|
||||||
inc(i);
|
if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then
|
||||||
|
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
|
||||||
|
If not CheckQuoted then
|
||||||
|
begin
|
||||||
|
// next string is not quoted; read until delimiter
|
||||||
|
j:=i;
|
||||||
|
while (j<=len) and
|
||||||
|
(AValue[j]<>aDelimiter) do inc(j);
|
||||||
|
Add( Copy(AValue,i,j-i));
|
||||||
|
i:=j;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
AddQuoted;
|
aNotFirst:=true;
|
||||||
i:=j+1;
|
|
||||||
end else begin
|
|
||||||
// next string is not quoted; read until delimiter
|
|
||||||
j:=i;
|
|
||||||
while (j<=len) and
|
|
||||||
(AValue[j]<>aDelimiter) do inc(j);
|
|
||||||
Add( Copy(AValue,i,j-i));
|
|
||||||
i:=j;
|
|
||||||
end;
|
end;
|
||||||
end else begin
|
|
||||||
if aNotFirst then Add('');
|
|
||||||
end;
|
|
||||||
aNotFirst:=true;
|
|
||||||
end;
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
while i<=len do begin
|
while i<=len do
|
||||||
// skip delimiter
|
begin
|
||||||
if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then inc(i);
|
// skip delimiter
|
||||||
|
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
|
||||||
// next string is quoted
|
if aNotFirst then Add('');
|
||||||
j:=i+1;
|
end
|
||||||
while (j<=len) and
|
else
|
||||||
( (AValue[j]<>aQuoteChar) or
|
begin
|
||||||
( (j+1<=len) and (AValue[j+1]=aQuoteChar) ) ) do begin
|
// next string is quoted
|
||||||
if (j<=len) and (AValue[j]=aQuoteChar) then inc(j,2)
|
if not CheckQuoted then
|
||||||
else inc(j);
|
begin
|
||||||
end;
|
// next string is not quoted; read until control character/space/delimiter
|
||||||
AddQuoted;
|
j:=i;
|
||||||
i:=j+1;
|
while (j<=len) and
|
||||||
end else begin
|
(Ord(AValue[j])>Ord(' ')) and
|
||||||
// next string is not quoted; read until control character/space/delimiter
|
(AValue[j]<>aDelimiter) do
|
||||||
j:=i;
|
inc(j);
|
||||||
while (j<=len) and
|
Add( Copy(AValue,i,j-i));
|
||||||
(Ord(AValue[j])>Ord(' ')) and
|
i:=j;
|
||||||
(AValue[j]<>aDelimiter) do inc(j);
|
end;
|
||||||
Add( Copy(AValue,i,j-i));
|
end;
|
||||||
i:=j;
|
// skip spaces
|
||||||
end;
|
while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do
|
||||||
end else begin
|
inc(i);
|
||||||
if aNotFirst then Add('');
|
aNotFirst:=true;
|
||||||
end;
|
end; // While I<=Len
|
||||||
|
end; // If StrictDelimiter
|
||||||
// skip spaces
|
|
||||||
while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do inc(i);
|
|
||||||
|
|
||||||
aNotFirst:=true;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
finally
|
finally
|
||||||
EndUpdate;
|
EndUpdate;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user