Jelajahi Sumber

* apply quoting patch for inifile from A. Klein

git-svn-id: trunk@15280 -
Almindor 15 tahun lalu
induk
melakukan
f18f1a60de
1 mengubah file dengan 25 tambahan dan 14 penghapusan
  1. 25 14
      packages/fcl-base/src/inifiles.pp

+ 25 - 14
packages/fcl-base/src/inifiles.pp

@@ -726,16 +726,7 @@ begin
           else
            begin
              sIdent:=Trim(Copy(sLine, 1,  j - 1));
-             sValue:=Trim(Copy(sLine, j + 1, Length(sLine) - j));
-             If StripQuotes then
-               begin
-               J:=Length(sValue);
-               // Joost, 2-jan-2007: The check (J>1) is there for the case that
-               // the value consist of a single double-quote character. (see
-               // mantis bug 6555)
-               If (J>1) and ((sValue[1] in ['"','''']) and (sValue[J]=sValue[1])) then
-                 sValue:=Copy(sValue,2,J-2);
-               end;  
+             sValue:=Trim(Copy(sLine, j + 1, Length(sLine) - j));  
            end;
         end;
         oSection.KeyList.Add(TIniFileKey.Create(sIdent, sValue));
@@ -748,15 +739,25 @@ function TIniFile.ReadString(const Section, Ident, Default: string): string;
 var
   oSection: TIniFileSection;
   oKey: TIniFileKey;
+  J: integer;
 begin
   Result := Default;
   oSection := FSectionList.SectionByName(Section,CaseSensitive);
   if oSection <> nil then begin
     oKey := oSection.KeyList.KeyByName(Ident,CaseSensitive);
     if oKey <> nil then
-      Result := oKey.Value;
+      If StripQuotes then
+      begin
+        J:=Length(oKey.Value);
+        // Joost, 2-jan-2007: The check (J>1) is there for the case that
+        // the value consist of a single double-quote character. (see
+        // mantis bug 6555)
+        If (J>1) and ((oKey.Value[1] in ['"','''']) and (oKey.Value[J]=oKey.Value[1])) then
+           Result:=Copy(oKey.Value,2,J-2);
+      end 
+      else Result:=oKey.Value;
+    end;
   end;
-end;
 
 procedure TIniFile.SetCacheUpdates(const AValue: Boolean);
 begin
@@ -856,7 +857,7 @@ procedure TIniFile.ReadSectionValues(const Section: string; Strings: TStrings);
 var
   oSection: TIniFileSection;
   s: string;
-  i: integer;
+  i,J: integer;
 begin
   Strings.BeginUpdate;
   try
@@ -864,7 +865,17 @@ begin
     oSection := FSectionList.SectionByName(Section,CaseSensitive);
     if oSection <> nil then with oSection.KeyList do
       for i := 0 to Count-1 do begin
-        s := Items[i].Ident+Separator+Items[i].Value;
+        s := Items[i].Value;
+      If StripQuotes then
+        begin
+          J:=Length(s);
+          // Joost, 2-jan-2007: The check (J>1) is there for the case that
+          // the value consist of a single double-quote character. (see
+          // mantis bug 6555)
+          If (J>1) and ((s[1] in ['"','''']) and (s[J]=s[1])) then
+             s:=Copy(s,2,J-2);
+        end;
+        s:=Items[i].Ident+Separator+s;
         Strings.Add(s);
       end;
   finally