You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I write a configuration to disk using "void writeFile(const char *filename);" comments are not preserved. This is a problem, because I'd like to edit files both with a text editor and libconfig (from a C++ program).
Is it possible to preserve comments?
Not with the current implementation, and this is by design. Please check the (fine) documentation, section 2.10:
"text.
Comments are ignored when the configuration is read in, so they are not treated as part
of the configuration. Therefore if the configuration is written back out to a stream, any
comments that were present in the original configuration will be lost."
This would be very hard to implement since comments can appear virtually anywhere in the configuration. I did consider some limited support for saving any comment that appeared directly before a setting, by attaching its text to the setting itself. So effectively every setting would have a "comment" property.
Just extend the config_setting_t structure to have "comment" property.
Each setting parse to the end of line. All the text after ';' mark that is detected as one line comment ("//" or "#") will be added to the property.
At the moment Iam using the lib like this to save comments which is ugly way:
pos_x = 5;
pox_x_comment = "This is comment";
Activity
jltallon commentedon Dec 21, 2015
Not with the current implementation, and this is by design. Please check the (fine) documentation, section 2.10:
"text.
Comments are ignored when the configuration is read in, so they are not treated as part
of the configuration. Therefore if the configuration is written back out to a stream, any
comments that were present in the original configuration will be lost."
hyperrealm commentedon Dec 23, 2015
This would be very hard to implement since comments can appear virtually anywhere in the configuration. I did consider some limited support for saving any comment that appeared directly before a setting, by attaching its text to the setting itself. So effectively every setting would have a "comment" property.
killdaclick commentedon Jun 15, 2018
Just extend the config_setting_t structure to have "comment" property.
Each setting parse to the end of line. All the text after ';' mark that is detected as one line comment ("//" or "#") will be added to the property.
At the moment Iam using the lib like this to save comments which is ugly way:
pos_x = 5;
pox_x_comment = "This is comment";
koziura commentedon Jul 2, 2019
how can i add a comment when writing?