0

When trying to replace the cout's I had used for debugging for a more elaborate logging function. I ran into the following problem:

A message currently is constructed like this:

testValue;
cout << "value" << testValue;

And should become this:

logger->log("value" + SSTR(testValue), program_component, 2);

Where SSTR is a custom macro that converts the in into a string.

What I don't know how to do however, is how to replace any number of outputs?

What I've got so far is this expression:

cout((?([^\r\n])\s)*\<\<(?([^\r\n])\s)*((?<string>(\".*?\"))|(?<id>(\b(_\w+|[\w-[0-9_]]\w*)\b))))*

and this replacement pattern:

log(${id}, programComponent, 2)

I'd really appreciate any help :)

Kind Regards, Lauris

laurisvr
  • 2,724
  • 6
  • 25
  • 44
  • What language shall that be? What are you trying to do? – Deduplicator Apr 30 '14 at 11:16
  • The coding language is c++. The regex parser is that of visual studio 2013. I am trying to switch from logging with the use of cout, to logging with a more elaborate logging function. – laurisvr Apr 30 '14 at 11:30
  • And you are sure `cout` is only used for logging? BTW: Does your more elaborate logging method not have a standard `istream` interface? – Deduplicator Apr 30 '14 at 11:34
  • Yes good thinking on the cout, but the intent is to replace all the cout and if neccessary remove them. And since more arguments are required, my own logging doesn't have a istream interface. – laurisvr Apr 30 '14 at 11:52
  • ?? You can save any information you want with an `istream`-interface. Perhaps you want to take a look at ``? AFAIK, the only place iostreams lack (besides maybe performance when synchronized with C files and threads) is internationalisation, which is not an issue for logging. – Deduplicator Apr 30 '14 at 12:05
  • Thanks again for your reply. Unfortunately logging function is already agreed upon. So I can't change that. Therefore I'm just wondering how to do the regex. – laurisvr Apr 30 '14 at 12:23
  • My advice then: Just use for the word `cout` and replace each occurence manually, or at least all non-trivial cases, as it is immensely versatile and thus your pattern would end up being unadvisable over-broad or much too restricted. Wish you luck. – Deduplicator Apr 30 '14 at 12:29

0 Answers0