[fpc-pascal] TInifile does not handle " " (space) as a value.

2017-08-04 Thread Torsten Bonde Christiansen

Dear List.

I was trying to use the ini file for our program to store a single space 
" " as a value, but this does not seem to be posible.


From the Wikipedia definition of INI file 
(https://en.wikipedia.org/wiki/INI_file#Whitespace) whitespace in values 
does not seem to be well defined, so it may just be a design choice.


The following illustrates the issue:

program Project1;

{$mode objfpc}{$H+}

uses
  Classes, IniFiles;

var
  Ini: TIniFile;
  S: String;
begin
  Ini := TIniFile.Create('/tmp/test.ini');
  Ini.WriteString('sec1', 'S', ' ');
  Ini.Free;

  Ini := TIniFile.Create('/tmp/test.ini');
  S := Ini.ReadString('sec1', 'S', 'ZZ'); // S is '' and not ' ' as 
expected

  Ini.Free;
end.


Is this considered a bug or "by design"?

Kind regards
Torsten Bonde Christiansen
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] TInifile does not handle " " (space) as a value.

2017-08-04 Thread Michael Van Canneyt



On Fri, 4 Aug 2017, Torsten Bonde Christiansen wrote:


Dear List.

I was trying to use the ini file for our program to store a single space 
" " as a value, but this does not seem to be posible.


From the Wikipedia definition of INI file 
(https://en.wikipedia.org/wiki/INI_file#Whitespace) whitespace in values 
does not seem to be well defined, so it may just be a design choice.


The following illustrates the issue:

program Project1;

{$mode objfpc}{$H+}

uses
  Classes, IniFiles;

var
  Ini: TIniFile;
  S: String;
begin
  Ini := TIniFile.Create('/tmp/test.ini');
  Ini.WriteString('sec1', 'S', ' ');
  Ini.Free;

  Ini := TIniFile.Create('/tmp/test.ini');
  S := Ini.ReadString('sec1', 'S', 'ZZ'); // S is '' and not ' ' as 
expected

  Ini.Free;
end.


Is this considered a bug or "by design"?


This is by design. 
As you said, whitespace is not so well defined.

Probably an option can be added not to trim whitespace, but I fear this will
lead to more inconsistencies.

As a workaround, try quoting your spaces, something like " "

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal