Skip to content

Preserving comments #35

Open
Open

Description

@qqwwaass

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?

Activity

  1. jltallon commented on Dec 21, 2015

    @jltallon
    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."

  2. hyperrealm commented on Dec 23, 2015

    @hyperrealm
    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.

  3. killdaclick commented on Jun 15, 2018

    @killdaclick

    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";

  4. koziura commented on Jul 2, 2019

    @koziura

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions