diff options
author | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2020-08-21 07:38:33 +0000 |
---|---|---|
committer | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2020-08-21 07:38:33 +0000 |
commit | e65c908d7c83415006277de6d6841d92eba043d2 (patch) | |
tree | 02943e933f66e203cfe1e27bf21613bdaddb2073 /rtl/objpas | |
parent | 131c3acb582ec5556b86a663ae999ae30d752d7e (diff) | |
download | fpc-e65c908d7c83415006277de6d6841d92eba043d2.tar.gz |
* Fix bug ID 0037605: Setting quotechar to NULL char disables quoting
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@46530 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'rtl/objpas')
-rw-r--r-- | rtl/objpas/classes/stringl.inc | 146 |
1 files changed, 76 insertions, 70 deletions
diff --git a/rtl/objpas/classes/stringl.inc b/rtl/objpas/classes/stringl.inc index b651dbafa1..fd1e234fa0 100644 --- a/rtl/objpas/classes/stringl.inc +++ b/rtl/objpas/classes/stringl.inc @@ -228,7 +228,6 @@ begin BreakChars:=[#0,QuoteChar,Delimiter] else BreakChars:=[#0..' ',QuoteChar,Delimiter]; - // Check for break characters and quote if required. For i:=0 to count-1 do begin @@ -242,7 +241,7 @@ begin inc(p); DoQuote:=(p<>pchar(S)+length(S)); end; - if DoQuote then + if DoQuote and (QuoteChar<>#0) then Result:=Result+QuoteString(S,QuoteChar) else Result:=Result+S; @@ -547,6 +546,27 @@ var Add(StringReplace(Copy(AValue,i+1,j-i-1),aQuoteChar+aQuoteChar,aQuoteChar, [rfReplaceAll])); 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 BeginUpdate; @@ -565,82 +585,68 @@ begin len:=length(AValue); If aStrictDelimiter then begin - while i<=Len do begin - // skip delimiter - if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then - inc(i); - - // read next string - if i<=len then begin - 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 + while i<=len do + begin + // skip delimiter + if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then + inc(i); + // read next string + if i>len then + begin + if aNotFirst then Add(''); + end + else begin - if (j<=len) and (AValue[j]=aQuoteChar) then - inc(j,2) - else - inc(j); + 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; - AddQuoted; - 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; + aNotFirst:=true; end; - end else begin - if aNotFirst then Add(''); - end; - aNotFirst:=true; - end; end else begin - while i<=len do begin - // skip delimiter - if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then inc(i); + while i<=len do + begin + // skip delimiter + if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then + inc(i); - // skip spaces - while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do inc(i); + // skip spaces + while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do inc(i); - // read next string - if i<=len then begin - 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 - 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 - j:=i; - while (j<=len) and - (Ord(AValue[j])>Ord(' ')) and - (AValue[j]<>aDelimiter) do inc(j); - Add( Copy(AValue,i,j-i)); - i:=j; - end; - end else begin - if aNotFirst then Add(''); - end; - - // skip spaces - while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do inc(i); - - aNotFirst:=true; - end; - end; + // read next string + if i>len then + begin + if aNotFirst then Add(''); + end + else + begin + // next string is quoted + if not CheckQuoted then + begin + // next string is not quoted; read until control character/space/delimiter + j:=i; + while (j<=len) and + (Ord(AValue[j])>Ord(' ')) and + (AValue[j]<>aDelimiter) do + inc(j); + Add( Copy(AValue,i,j-i)); + i:=j; + end; + end; + // skip spaces + while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do + inc(i); + aNotFirst:=true; + end; // While I<=Len + end; // If StrictDelimiter finally EndUpdate; end; |