Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserving comments #35

Open
qqwwaass opened this issue Nov 22, 2015 · 4 comments
Open

Preserving comments #35

qqwwaass opened this issue Nov 22, 2015 · 4 comments

Comments

@qqwwaass
Copy link

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?

@jltallon
Copy link
Collaborator

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
Copy link
Owner

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
Copy link

killdaclick commented 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
Copy link

koziura commented Jul 2, 2019

how can i add a comment when writing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants