Monday, August 15, 2011

C++ pull in a text file parse/split each line depending on a particular token?

regex is not really suited for this task. For parsing I recommend (and use extensively in my company's products) a href="http://www.boost.org/doc/libs/1_42_0/libs/tokenizer/index.html" rel="nofollow"http://www.boost.org/doc/libs/1_42_0/lib…/a (for simple tasks like tokenize on these tokens, consume these delimiters, keep those, unescape escaped delimiters, etc) and a href="http://www.boost.org/doc/libs/1_42_0/libs/spirit/doc/html/index.html" rel="nofollow"http://www.boost.org/doc/libs/1_42_0/lib…/a (for serious tasks like parsing a config file grammar or, as in your case, expression syntax. The latter (boost.spirit) makes reading such files a breeze if you can get the hang of it, although I suppose you'd call it "overkill" :) They have examples for reading expressions, I think.

No comments:

Post a Comment