I'm writing a parser for Windows driver inf files. They are similar to ini files, with some odd things about them.
The part I'm struggling with right now is that if a line contains a ;
anywhere in the line, it's considered a comment.
However, if it's surrounded by "
, then it's a string. Anything inside "
is literal and an actual string.
And to make things more interesting, if you want to have a literal "
inside a string, you need to precede it with another "
.
So in other words:
"This is a string" ;This is a comment
"This is a string; which contains a semicolon"
"This is a string; which contains a semicolon" ;And a comment
"This is a string; which contains a semicolon and a double quote """
"These are", "two strings with ""double quotes""" ;And a comment
What's the easiest way to determine whether there is a comment in the line and also to extract the strings from the lines?
I imagine this might be regex, but not sure if that's the best way so I'm open to ideas.