Browse Source

* 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 -

michael 5 years ago
parent
commit
c72cd8ef67
1 changed files with 76 additions and 70 deletions
  1. 76 70
      rtl/objpas/classes/stringl.inc

+ 76 - 70
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;