-
Notifications
You must be signed in to change notification settings - Fork 107
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
Support for semicolon comment delimiter #22
base: develop
Are you sure you want to change the base?
Conversation
INI style configuration files should support the semicolon ';' character, when it is the first character on the line only, as a comment delimiter. Because the '#' style comments are not allowed in strict MS INI files, this gives an opening for files to be compatible in both and still have comments.
This could, in theory, cause errors in existing files...if there are valid lines/values that start with semi-colons. I suspect there are very close to zero instances where this is the case, because that would be a weird thing to do. More realistically, there are people who have files with what they think are comments, but the lines are actually being processed. Either way, if we don't want to change the file format in this minor way, we can add another defaulted parameter (defaulting it off) to the parse_config_file interface. |
This seems reasonable to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why check for a semicolon before, rather than after, trimming whitespace? If we support
#
comments (which are not integral to the INI format AFAICR), and if we trim whitespace before really processing a line, let's also consider;blah blah blah
to be a comment. - The original code uses
*s.begin()
instead of*s.at(0)
, I suggest maintaining uniformity in this respect. - Given the current choice of when to check for the semicolon, why go through whitespace trimming, instead of continuing to the next loop iteration immediately?
The code I'd put in here would be:
s = trim_ws(s);
if (!s.empty()) {
if (*s.begin() == ';') {
continue; // an INI-style comment line
}
/* etc. etc. */
This has been fixed 4 years ago. Why is this not yet merged into the latest Boost release? |
There are outstanding questions above, as you can see. |
Ok, let me see if I understood correctly the open issues.
According to Wiki:
So it would actually be wrong to make sure a line starting with a semicolon would be interpreted as a valid setting. If you read on in the Wiki article, you notice it would make much more sense to optionally interpret the number sign as a comment instead, since by default it should only be interpreted as a pseudo line comment character, hiding a setting by changing it's name. On stackoverflow.com there is a related thread concerning this topic. The current implementation
should be just fine. Am I missing something? |
My questions. |
The documentation I've found says something along the line of "semicolon at the start of the line". I feel like trimming white space before it could potentially cause issues. Though the only use case I can think of is where someone wants a single semicolon as the contents of a value....not super useful, but I want to be careful as people might be depending on weird side effects of semicolons not working as a comment other places in the line. Point taken on If we don't change it to remove the white space before checking for a comment line, there's no harm in doing it after, as the empty string won't have any. |
Well, emphasizing again that it's Vladimir's call, not mine. But:
Well, there's no official spec, so ok I guess.
... but it's useless work. |
@eyalroz I've updated, does that look good to you? |
s = trim_ws(s); | ||
// if the first character is a ';' line is a comment | ||
if (!s.empty() && ';' == *s.begin()) { | ||
s = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just do continue;
here?
@@ -267,6 +267,7 @@ void test_config_file(const char* config_file) | |||
|
|||
const char content1[] = | |||
" gv1 = 0#asd\n" | |||
"; semi comment\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A also want to see a commented-out line which has an assignment, and a check to ensure the value is not assigned.
Other than a couple of nitpicks, yes. But again - you're asking the wrong person :-) |
I am happy to see there is some more activity in this thread. Unfortunately @vprus: Do you have any more doubts and suggestions or is this code ready to be merged? |
INI style configuration files should support the semicolon ';' character, when
it is the first character on the line only, as a comment delimiter. Because
the '#' style comments are not allowed in strict MS INI files, this gives an
opening for files to be compatible in both and still have comments.