Re: [Boost-users] replace_all_regex on c-string help

But for some reason, I need to perform replacement on a C-string (char *), is replace_all_regex safe to do so? Will replace_all_regex handle memory issue for us?
Of course this would be impossible. Boost.Regex can't know how the memory was allocated (e.g. malloc or new or some custom allocator), or even if it *was* allocated.
Why do you need to operate on raw char*'s? Why can't you operate on an std::string?
I got the string (char*s), which is too big (>10M), from an external library, it's too slow to convert the raw string to std::string before it is handled by replace_all_regex

I got the string (char*s), which is too big (>10M), from an external library, it's too slow to convert the raw string to std::string before it is handled by replace_all_regex
Here's your fundamental problem: regex does not do in-place search and replace. Further: * Any attempt to do so on a fixed size buffer runs the risk of buffer over-run errors, the *best* that you might hope for is that the application only crashes infrequently! * In-place replace is often slower than copying: all that shuffling of characters around in the buffer as the size of each matched section is adjusted is a time-killer. In the worst case it's O(N^2), where as copying is amortized O(N). You can clearly use your C-string as the source for the regex search and replace, but the destination must be somewhere else. Could be a string, could be a vector<char>, could be a stream, could be.... whatever. John.
participants (2)
-
John Maddock
-
llwaeva@21cn.com