Regex to capture / filter comma separated function arguments to refactor c++ source file

  automated-refactoring, c++, regex

I’ve been trying without success to create a regex that I can use to refactor a bunch of calls to 2 functions with a fixed, 6 argument signature like this:

logger_4args_A(FlagsA|FlagsB,"This is %s message %d",someString(n*2)[4],some_Goofy->number.thing(),0,0);
logger_4args_B(FlagsC, "No args passed here, only 0 defaults",0,0,0,0);

into a variadic invocation of 2 new functions like this:

newLogA(FlagsA|FlagsB,"This is %s message %d",someString(n*2)[4],some_Goofy->number.thing());
newLogB(FlagsC, "No real args passed only 0 defaults");

(… effectively a printf()).

The logger_4args_x functions always take a 6 args and the function I want replace take
this seems like it should be easy but has made me realize my true grasp of RE drops off much more quickly than I thought 🙁

A couple of points that hopefully simplify things:

  • 0 will never be an actual argument
  • Real items will always appear first: data1,data2,0,0 NEVER data1,0,data2,0
  • There will never be literals "" or ” as an argument
  • There are no C Preprocessor macros in the argument list

I’ve been able to capture everything up to the zeros, but no permutation of lookahead / lookbehind / branch reset capture groups has worked for me.
Thanks for any help or suggestions!

Source: Windows Questions C++

LEAVE A COMMENT