Boost logo

Boost Users :

Subject: Re: [Boost-users] best tool in Boost for (massive) string replacement?
From: michi7x7 (mailing-lists_at_[hidden])
Date: 2010-09-24 12:45:12


  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<string,string> 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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net