Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2006-07-30 12:05:04


llwaeva_at_[hidden] wrote:
> Hi there,
> boost:regex is powerful in string replacing. I am working with a
> complicate case which need a faster method in replacing substring.
> Here
> is my problem.
>
> I have a big string contains some pattern %K{xxx}, where xxx is a
> filename which may vary from place to place. e.g.

> Any better idea for my problem?

I suggest you enumerate through the regular expression matches and for each
match:

1) Copy everything from the end of the last match (or the start of the
string) to the new buffer.
2) Read the filename, and copy the contents of the filename to the new
string.
3) Loop and continue.

The code would be almost exactly the same as the internals of regex_replace
if that helps.

You could also improve matters slightly by calling std::string::reserve on
the new string before starting.

John.


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