[regex] Context-sensitive replacement of text using regex_replace

I've been struggling with a problem with using regex_replace this afternoon, and I would appreciate some pointers on properly using the regex package. I've got a file that is similar to a CSS style sheet (it's actually a Qt style sheet) that contains color entries that similar to: rgb( 200, 255, 200 ). I've already successfully written some code that finds these patterns and replaced them with statically determined text, just to verify that I was able to locate them all properly. I have an application in which the color scheme of the user interface (specified in the style sheet) has to change between a daytime and nighttime color scheme. The nighttime color scheme is derived from the daytime color scheme by reducing the luminance of the colors. I'd like to generate the nighttime color scheme from the daytime scheme by extracting the components of the color and applying a calculation to them, then replacing the original text with the new text. The examples on the Boost site for regex_replace all demonstrate replacement with static text. I suspect that I have to do some sort of combination using regex_replace, regex_iterator, and match_results, but I can't quite wrap my head around the documentation for these classes to see how they interoperate. I would appreciate some pointers as to how to proceed.

KEN RODE wrote:
I've been struggling with a problem with using regex_replace this afternoon, and I would appreciate some pointers on properly using the regex package.
I've got a file that is similar to a CSS style sheet (it's actually a Qt style sheet) that contains color entries that similar to: rgb( 200, 255, 200 ). I've already successfully written some code that finds these patterns and replaced them with statically determined text, just to verify that I was able to locate them all properly.
I have an application in which the color scheme of the user interface (specified in the style sheet) has to change between a daytime and nighttime color scheme. The nighttime color scheme is derived from the daytime color scheme by reducing the luminance of the colors. I'd like to generate the nighttime color scheme from the daytime scheme by extracting the components of the color and applying a calculation to them, then replacing the original text with the new text.
The examples on the Boost site for regex_replace all demonstrate replacement with static text. I suspect that I have to do some sort of combination using regex_replace, regex_iterator, and match_results, but I can't quite wrap my head around the documentation for these classes to see how they interoperate. I would appreciate some pointers as to how to proceed.
This sort of this is much more easily accomplished with Boost.Xpressive,
which permits little lambda-like substitution expressions. Here is a
little program to get you started. It computes a new sub substitution
string by subtracting each rgb value from 300.
#include <string>
#include <iostream>
#include

The examples on the Boost site for regex_replace all demonstrate replacement with static text. I suspect that I have to do some sort of combination using regex_replace, regex_iterator, and match_results, but I can't quite wrap my head around the documentation for these classes to see how they interoperate. I would appreciate some pointers as to how to proceed.
Hi Ken, what I suggest you do is look at the source for regex_replace: it's actually a pretty simple application of of regex_iterator internally, it should be fairly trivial to modify that to do what you want it to, HTH, John.

I'd like to thank Eric and John for their suggestions regarding my regex_replace issue. My solution was ultimately an adaptation of the regex_replace function, as suggested by John. Visual studio refused to cooperate with compiling the code snippet that you wrote for me, Eric, but I surely do appreciate your having taken the time to write it. Many thanks, guys. John Maddock wrote:
The examples on the Boost site for regex_replace all demonstrate replacement with static text. I suspect that I have to do some sort of combination using regex_replace, regex_iterator, and match_results, but I can't quite wrap my head around the documentation for these classes to see how they interoperate. I would appreciate some pointers as to how to proceed.
Hi Ken, what I suggest you do is look at the source for regex_replace: it's actually a pretty simple application of of regex_iterator internally, it should be fairly trivial to modify that to do what you want it to,
HTH, John. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Ken Rode wrote:
I'd like to thank Eric and John for their suggestions regarding my regex_replace issue. My solution was ultimately an adaptation of the regex_replace function, as suggested by John.
Glad that your problem is solved.
Visual studio refused to cooperate with compiling the code snippet that you wrote for me, Eric, but I surely do appreciate your having taken the time to write it.
Strange, I used Visual C++ to verify the code before I posted it. What compiler version are you using? I used VC9. Could you post the errors?
Many thanks, guys.
My pleasure. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric Niebler wrote:
Ken Rode wrote:
Visual studio refused to cooperate with compiling the code snippet that you wrote for me, Eric, but I surely do appreciate your having taken the time to write it.
Strange, I used Visual C++ to verify the code before I posted it. What compiler version are you using? I used VC9. Could you post the errors?
Ken? -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (4)
-
Eric Niebler
-
John Maddock
-
Ken Rode
-
KEN RODE