Forum > FPC development

TiniFile alters inifile comments

(1/2) > >>

klyxmaster:
Hi, hope this is in the correct thread :-)

I am using Tinifile, love it.
problem: it is altering two things:
1. removing the whitespace
2. altering the comment lines

example

##################
# this is a comment line
#
# more comment lines
#############
---whitespace here (blank line) -----
key=some data
--whitespace here (blank line) -----
#################
#
# more comments
#
##############

what fpc does to it:

=#################
=# this is a comment line
=#
=# more comment lines
=#############
key=some data (notice whitespace above and below are now gone)
=#################
=#
=# more comments
=#
=##############

this is when i use the line ini.writestring([newdata here])
 
Fortuneately, the app that uses the ini file, seems to be unaffected by these comment changes, and white space, however, I prefer it not to do that.
is there osmething I can do to prevent these changes?

typo:
AFAICS, if you include in a line an equal sign, nothing is altered on that line, no matter it has text or not. Blank lines are removed.

I don't know whether this behavior is by design or can be considered a bug.

You could make your comments so, for instance:


--- Code: ---[section]
==================
=====COMMENT======
==================
key=value
key with spaces=value with spaces

--- End code ---

Spaces after the equal sign and spaces which begin lines are also removed.

howardpc:

--- Quote from: typo on August 17, 2014, 08:52:29 am ---Blank lines are removed.
I don't know whether this behavior is by design or can be considered a bug.

--- End quote ---

I'm sure this is by design, not a bug, because some legacy INI implementations do not allow blank lines.
The INI format is a rather informal standard, which since it was deprecated by M$ in favour of the Registry has no international company or organisation to encourage/enforce compatibility with a specific implementation standard (unlike JSON or XML).

nsl:
In INI files if the first character on a line is a semi-colon (;) then that line is taken to be a comment.
If looks like lines starting with a '#' are taken to be values with an empty key so that when they are written back out the key-value separator (the '=') is added to the start of the string   

klyxmaster:
Good replies and all true. I remember the good ole days LOL
Yes it is true ini,cfg etc files used to start with ";" as a "standard" in comments
whitespace was still iffy, whether it was allowed.

@typo, unfortunately, I am working with existing projects - and the ini files have their own standard for the last several years. They are just large and I wrote a simple editor that allows a user to pick one of the ini files, and edit. Just easier than opening notepad over and over and scanning through long lines of config settings.

so far it doesn't seem to affect the app.

anyone have a trick to prevent the "=#" scenario? I can probably live without the whitespace, as to this day, no config file uses it.


Navigation

[0] Message Index

[#] Next page

Go to full version