Browse Source

--- Merging r15280 into '.':
U packages/fcl-base/src/inifiles.pp
--- Merging r15292 into '.':
G packages/fcl-base/src/inifiles.pp
--- Merging r15436 into '.':
G packages/fcl-base/src/inifiles.pp

# revisions: 15280,15292,15436
------------------------------------------------------------------------
r15280 | Almindor | 2010-05-16 12:35:42 +0200 (Sun, 16 May 2010) | 2 lines
Changed paths:
M /trunk/packages/fcl-base/src/inifiles.pp

* apply quoting patch for inifile from A. Klein

------------------------------------------------------------------------
------------------------------------------------------------------------
r15292 | jonas | 2010-05-18 18:55:18 +0200 (Tue, 18 May 2010) | 3 lines
Changed paths:
M /trunk/packages/fcl-base/src/inifiles.pp

* fixed TIniFile.ReadString in case an unquoted string was read while
StripQuotes is true after r15280 (mantis #16502, patch by Ingo Steiniger)

------------------------------------------------------------------------
------------------------------------------------------------------------
r15436 | marco | 2010-06-14 14:24:12 +0200 (Mon, 14 Jun 2010) | 1 line
Changed paths:
M /trunk/packages/fcl-base/src/inifiles.pp

* do not prefix inifile.readsectionvalues results with '=' when key='' (Delphi TMeminifile compatible. API based Delphi TInifile refuses to read such files)
------------------------------------------------------------------------

git-svn-id: branches/fixes_2_4@15441 -

marco 15 years ago
parent
commit
a89dceb3d2
1 changed files with 36 additions and 22 deletions
  1. 36 22
      packages/fcl-base/src/inifiles.pp

+ 36 - 22
packages/fcl-base/src/inifiles.pp

@@ -122,7 +122,7 @@ type
     FFileName: string;
     FSectionList: TIniFileSectionList;
     FEscapeLineFeeds: boolean;
-    FCaseSensitive : Boolean; 
+    FCaseSensitive : Boolean;
     FStripQuotes : Boolean;
   public
     constructor Create(const AFileName: string; AEscapeLineFeeds : Boolean = False); virtual;
@@ -332,13 +332,13 @@ begin
     If CaseSensitive then
       begin
       for i := 0 to Count-1 do
-        if Items[i].Ident=AName then 
+        if Items[i].Ident=AName then
           begin
           Result := Items[i];
           Break;
           end;
       end
-    else  
+    else
       for i := 0 to Count-1 do
         if CompareText(Items[i].Ident, AName) = 0 then begin
           Result := Items[i];
@@ -408,7 +408,7 @@ begin
     If CaseSensitive then
       begin
       for i:=0 to Count-1 do
-        if (Items[i].Name=AName) then 
+        if (Items[i].Name=AName) then
           begin
           Result := Items[i];
           Break;
@@ -416,7 +416,7 @@ begin
       end
     else
       for i := 0 to Count-1 do
-        if CompareText(Items[i].Name, AName) = 0 then 
+        if CompareText(Items[i].Name, AName) = 0 then
           begin
           Result := Items[i];
           Break;
@@ -627,12 +627,12 @@ begin
   FStream := nil;
   slLines := TStringList.Create;
   try
-    if FileExists(FFileName) then 
+    if FileExists(FFileName) then
       begin
       // read the ini file values
       slLines.LoadFromFile(FFileName);
       FillSectionList(slLines);
-      end 
+      end
   finally
     slLines.Free;
   end;
@@ -727,15 +727,6 @@ begin
            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;  
            end;
         end;
         oSection.KeyList.Add(TIniFileKey.Create(sIdent, sValue));
@@ -748,15 +739,27 @@ 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)
+        else
+           Result:=oKey.Value;
+      end
+      else Result:=oKey.Value;
+    end;
   end;
-end;
 
 procedure TIniFile.SetCacheUpdates(const AValue: Boolean);
 begin
@@ -856,7 +859,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 +867,18 @@ 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;
+        if Items[i].Ident<>'' then
+          s:=Items[i].Ident+Separator+s;
         Strings.Add(s);
       end;
   finally
@@ -905,10 +919,10 @@ var
  oKey: TIniFileKey;
 begin
   oSection := FSectionList.SectionByName(Section,CaseSensitive);
-  if oSection <> nil then 
+  if oSection <> nil then
     begin
     oKey := oSection.KeyList.KeyByName(Ident,CaseSensitive);
-    if oKey <> nil then 
+    if oKey <> nil then
       begin
       oSection.KeyList.Delete(oSection.KeyList.IndexOf(oKey));
       oKey.Free;