Browse Source

* ifoWriteString boolean renamed to ifoStringBoolean., read will now also observe ifoStringBoolean. Fix issue #39625

Michaël Van Canneyt 3 years ago
parent
commit
ce20ba23fa
2 changed files with 27 additions and 6 deletions
  1. 17 6
      packages/fcl-base/src/inifiles.pp
  2. 10 0
      packages/fcl-base/tests/tcinifile.pp

+ 17 - 6
packages/fcl-base/src/inifiles.pp

@@ -134,14 +134,15 @@ type
     property Items[Index: integer]: TIniFileSection read GetItem; default;
   end;
 
-  TIniFileOption = (ifoStripComments,    // Strip comments when reading file
-                    ifoStripInvalid,     // Strip invalid lines when reading file.
-                    ifoEscapeLineFeeds, // Escape linefeeds when reading file.
-                    ifoCaseSensitive,   // Use Case sensitive section/key names
-                    ifoStripQuotes,     // Strip quotes when reading string values.
+  TIniFileOption = (ifoStripComments,        // Strip comments when reading file
+                    ifoStripInvalid,         // Strip invalid lines when reading file.
+                    ifoEscapeLineFeeds,      // Escape linefeeds when reading file.
+                    ifoCaseSensitive,        // Use Case sensitive section/key names
+                    ifoStripQuotes,          // Strip quotes when reading string values.
                     ifoFormatSettingsActive, // Use format settings when writing date/float etc.
-                    ifoWriteStringBoolean // Write booleans as string
+                    ifoStringBoolean         // Read/Write booleans as string
                     );
+
   TIniFileOptions = Set of TIniFileOption;
 
   TSectionValuesOption = (svoIncludeComments,svoIncludeInvalid, svoIncludeQuotes);
@@ -261,6 +262,9 @@ type
     procedure SetStrings(List: TStrings);
   end;
 
+Const
+  ifoWriteStringBoolean = ifoStringBoolean;
+
 implementation
 
 Resourcestring
@@ -722,6 +726,13 @@ begin
       else if IndexOfString(FBoolFalseStrings,S)>=0 then
         Result:=False
       end
+    else if (ifoWriteStringBoolean in FOptions) then
+      begin
+      if SameText(s,'true') then
+        Result:=True
+      else if SameText(s,'false') then
+        Result:=False
+      end
     else
       Result := CharToBool(s[1]);
 end;

+ 10 - 0
packages/fcl-base/tests/tcinifile.pp

@@ -79,6 +79,16 @@ begin
   AssertEquals('No string match, default',false,Ini.ReadBool('a','b',false));
   Ini.SetBoolStringValues(true,['t','true']);
   AssertEquals('No string match, default',false,Ini.ReadBool('a','b',false));
+  Ini.SetBoolStringValues(true,[]);
+  Ini.SetBoolStringValues(False,[]);
+  Ini.Options:=Ini.Options+[ifoWriteStringBoolean];
+  Ini.WriteString('a','b','true');
+  AssertEquals('ifoWriteStringBoolean, true string ',True,Ini.ReadBool('a','b',false));
+  Ini.WriteString('a','b','false');
+  AssertEquals('ifoWriteStringBoolean, false string',false,Ini.ReadBool('a','b',true));
+  Ini.WriteString('a','b','soso');
+  AssertEquals('ifoWriteStringBoolean, No string match, default',True,Ini.ReadBool('a','b',true));
+
 end;
 
 procedure TTestIniFile.SetUp;