5 Commits

Author SHA1 Message Date
Luke Shumaker
82fa79c786 option_parser.c: Allow comments on lines with quoted strings.
The current behavior is
 - If the value contains a double-quote:
   - 1. Verify that it must contains at least two quotes.
   - 2. If one of the quotes is the first character, trim it.
   - 3. If one of the quotes is the last character, trim it.
 - Else:
   - 1. Trim a trailing comment from the value.

This has the effect that

    `key = "value" # comment` => `value" #comment`

This is surprising and almost certainly not what the user wants.

However, it allows simple nested quotes like:

    `key = "A string "with quotes""` => `A string "with quotes"`

Fix the brokenness of the first example at the expense of breaking the
second.  A user seeking that value will now have to type:

    key = "A string \"with quotes\""

Do this by treating double-quote as a toggle that simply changes whether
`;` and `#` start comments (not too different than Bash using it to toggle
field separation).

In order to have strings that contain a literal double-quote, add
rudimentary support for backslash-escaping.  For now, only recognize
double-quote and backslash-itself; anything else is undefined; and the
program is free to do whatever it likes with them; for now, silently treat
the backslash as an ordinary character.

Note that this formulation of quoting implies that backslash-escaping works
identically both inside and outside of quotes.
2017-02-26 09:35:06 -05:00
Nikos Tsipinakis
d8d267e1f0 ASSERT_FALSE(expr == NULL) -> ASSERT(expr)
Simplify assert calls to improve code readability.
2017-02-23 20:45:09 +02:00
Nikos Tsipinakis
f34b846041 Fix memory leaks in the unit tests
Making valgrind complain less should help finding actual memory leaks in
the long run.
2017-01-29 15:32:36 +02:00
Nikos Tsipinakis
187d3f9ab9 Invalid boolean values should fall back to the default
Previously, an invalid value was always false
2016-12-15 19:13:08 +02:00
Nikos Tsipinakis
b9619a1460 Add option parser test suite 2016-12-03 19:33:40 +02:00