TInifile does not handle " " (space) as a value.

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

TInifile does not handle " " (space) as a value.

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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: TInifile does not handle " " (space) as a value.

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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: TInifile does not handle " " (space) as a value.

Graeme Geldenhuys-6
On 2017-08-04 08:47, Michael Van Canneyt wrote:
>> Is this considered a bug or "by design"?
> This is by design.
> As you said, whitespace is not so well defined.


Torsten, if you can, maybe switch to JSON files for config setting
instead. I have had fantastic success with JSON files in such a way. If
it doesn't yet exist (it probably does), one could write a API wrapper
(think Adapter design pattern) giving JSON files the same or very
similar interface to TINIFile - it could be handy for a transition period.

Regards,
   Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: TInifile does not handle " " (space) as a value.

Michael Van Canneyt


On Mon, 14 Aug 2017, Graeme Geldenhuys wrote:

> On 2017-08-04 08:47, Michael Van Canneyt wrote:
>>> Is this considered a bug or "by design"?
>> This is by design.
>> As you said, whitespace is not so well defined.
>
>
> Torsten, if you can, maybe switch to JSON files for config setting
> instead. I have had fantastic success with JSON files in such a way. If
> it doesn't yet exist (it probably does), one could write a API wrapper
> (think Adapter design pattern) giving JSON files the same or very
> similar interface to TINIFile - it could be handy for a transition period.

Actually, I have that class on my todo list...

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: TInifile does not handle " " (space) as a value.

Michael Van Canneyt
In reply to this post by Graeme Geldenhuys-6


On Mon, 14 Aug 2017, Graeme Geldenhuys wrote:

> On 2017-08-04 08:47, Michael Van Canneyt wrote:
>>> Is this considered a bug or "by design"?
>> This is by design.
>> As you said, whitespace is not so well defined.
>
>
> Torsten, if you can, maybe switch to JSON files for config setting
> instead. I have had fantastic success with JSON files in such a way. If
> it doesn't yet exist (it probably does), one could write a API wrapper
> (think Adapter design pattern) giving JSON files the same or very
> similar interface to TINIFile - it could be handy for a transition period.

You ask, we deliver. Revision 36913, package fcl-json.

Unit jsonini.pp contains TJSONIniFile. It is a descendent of TCustomIniFile.

Class method TJSONIniFile.ConvertIni will convert an .ini file to a .json file.
It attempts to use native types when possible.

ini2json example program included.

One item scratched off my long TODO list ;)

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: TInifile does not handle " " (space) as a value.

Free Pascal - General mailing list

Am 15.08.2017 11:17 schrieb "Michael Van Canneyt" <[hidden email]>:
>
>
>
> On Mon, 14 Aug 2017, Graeme Geldenhuys wrote:
>
>> On 2017-08-04 08:47, Michael Van Canneyt wrote:
>>>>
>>>> Is this considered a bug or "by design"?
>>>
>>> This is by design.
>>> As you said, whitespace is not so well defined.
>>
>>
>>
>> Torsten, if you can, maybe switch to JSON files for config setting instead. I have had fantastic success with JSON files in such a way. If it doesn't yet exist (it probably does), one could write a API wrapper (think Adapter design pattern) giving JSON files the same or very similar interface to TINIFile - it could be handy for a transition period.
>
>
> You ask, we deliver. Revision 36913, package fcl-json.
>
> Unit jsonini.pp contains TJSONIniFile. It is a descendent of TCustomIniFile.
>
> Class method TJSONIniFile.ConvertIni will convert an .ini file to a .json file.
> It attempts to use native types when possible.
>
> ini2json example program included.
>
> One item scratched off my long TODO list ;)

Not entirely: "make install" fails. It complains about missing jsonini.rst file :P

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: TInifile does not handle " " (space) as a value.

Michael Van Canneyt


On Tue, 15 Aug 2017, Sven Barth via fpc-pascal wrote:

> Am 15.08.2017 11:17 schrieb "Michael Van Canneyt" <[hidden email]>:
>>
>>
>>
>> On Mon, 14 Aug 2017, Graeme Geldenhuys wrote:
>>
>>> On 2017-08-04 08:47, Michael Van Canneyt wrote:
>>>>>
>>>>> Is this considered a bug or "by design"?
>>>>
>>>> This is by design.
>>>> As you said, whitespace is not so well defined.
>>>
>>>
>>>
>>> Torsten, if you can, maybe switch to JSON files for config setting
> instead. I have had fantastic success with JSON files in such a way. If it
> doesn't yet exist (it probably does), one could write a API wrapper (think
> Adapter design pattern) giving JSON files the same or very similar
> interface to TINIFile - it could be handy for a transition period.
>>
>>
>> You ask, we deliver. Revision 36913, package fcl-json.
>>
>> Unit jsonini.pp contains TJSONIniFile. It is a descendent of
> TCustomIniFile.
>>
>> Class method TJSONIniFile.ConvertIni will convert an .ini file to a .json
> file.
>> It attempts to use native types when possible.
>>
>> ini2json example program included.
>>
>> One item scratched off my long TODO list ;)
>
> Not entirely: "make install" fails. It complains about missing jsonini.rst
> file :P

Already fixed too :)

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: TInifile does not handle " " (space) as a value.

Graeme Geldenhuys-6
In reply to this post by Michael Van Canneyt
On 2017-08-15 10:17, Michael Van Canneyt wrote:
> You ask, we deliver. Revision 36913, package fcl-json.
>
> Unit jsonini.pp contains TJSONIniFile. It is a descendent of TCustomIniFile.


What a show off!!!  :-P

hehehe.... Nicely done Michael, that was very fast. :)


Regards,
   Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: TInifile does not handle " " (space) as a value.

Michael Van Canneyt


On Tue, 15 Aug 2017, Graeme Geldenhuys wrote:

> On 2017-08-15 10:17, Michael Van Canneyt wrote:
>> You ask, we deliver. Revision 36913, package fcl-json.
>>
>> Unit jsonini.pp contains TJSONIniFile. It is a descendent of
> TCustomIniFile.
>
>
> What a show off!!!  :-P
>
> hehehe.... Nicely done Michael, that was very fast. :)

Well, it was on my TODO list anyway.
I was glad to be able to tick it off, it was fun to do.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: TInifile does not handle " " (space) as a value.

Free Pascal - General mailing list
In reply to this post by Michael Van Canneyt

Am 15.08.2017 11:57 schrieb "Michael Van Canneyt" <[hidden email]>:
>
>
>
> On Tue, 15 Aug 2017, Sven Barth via fpc-pascal wrote:
>
>> Am 15.08.2017 11:17 schrieb "Michael Van Canneyt" <[hidden email]>:
>>>
>>>
>>>
>>>
>>> On Mon, 14 Aug 2017, Graeme Geldenhuys wrote:
>>>
>>>> On 2017-08-04 08:47, Michael Van Canneyt wrote:
>>>>>>
>>>>>>
>>>>>> Is this considered a bug or "by design"?
>>>>>
>>>>>
>>>>> This is by design.
>>>>> As you said, whitespace is not so well defined.
>>>>
>>>>
>>>>
>>>>
>>>> Torsten, if you can, maybe switch to JSON files for config setting
>>
>> instead. I have had fantastic success with JSON files in such a way. If it
>> doesn't yet exist (it probably does), one could write a API wrapper (think
>> Adapter design pattern) giving JSON files the same or very similar
>> interface to TINIFile - it could be handy for a transition period.
>>>
>>>
>>>
>>> You ask, we deliver. Revision 36913, package fcl-json.
>>>
>>> Unit jsonini.pp contains TJSONIniFile. It is a descendent of
>>
>> TCustomIniFile.
>>>
>>>
>>> Class method TJSONIniFile.ConvertIni will convert an .ini file to a .json
>>
>> file.
>>>
>>> It attempts to use native types when possible.
>>>
>>> ini2json example program included.
>>>
>>> One item scratched off my long TODO list ;)
>>
>>
>> Not entirely: "make install" fails. It complains about missing jsonini.rst
>> file :P
>
>
> Already fixed too :)

Thanks!

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Loading...