
Am 24.09.2010 00:11, schrieb alfC:
With all the tools available in Boost and coming from a different backgroup is hard for me to choose what is the best tool in Boost to do a massive string replacement.
The problem I have is the following, I have a map of replaced and replacing strings
std::map
rep; rep["\\alpha"] = "a"; rep["\\beta"] = "b"; ... let's say about 100 of these. And I have an input/output file (few thousand lines) were I would like to do all this replacements. What is the best tool in boost to do this, Spirit, Regex, tokenizer, StringAlgorithm?
My only approach so far is Regex and the implementation is very crude. I read the file line by line and do a loop over the replacement keys for each line. It is not even exploiting the fact that I have a map of replacements (compared to an array of replacements). It seems very slow.
(Yes, it is like a 'sed' unix command replacement but with hundreds of replacement strings)
Thank you, Alfredo Hi,
Spirit should do that quite fast, but of course it's difficult to know which one is fastest. Spirit-Code can be optimized during compilation, so make sure to use a static const map, if possible. Regards, michi7x7