-1

I want to convert C style LOGD("hello"); to LOGD<<"hello";

in eclipse find/replace.

how can I do that?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

3 Answers3

0

You may try the following find and replace, in regex mode:

Find:

LOGD\("([^"]*)"\);

Replace:

LOGD << "$1";

We capture the text of the string input into LOGD in your code, and then use it as the RHS of the << operator in the replacement. The (first) capture group is made available as $1.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

While a regexp may be Ok, I recommend to use a macro or better a template inline function rather than a regexp conversion:

#define LOGD(x) LOGD_CPP<<(x)

or

template<typename X> inline void LOGD(const X &x) {LOGD_CPP<<x;}

The reason is to be compliant with possible syntax complications inside x (nested parentheses, lambda-functions etc.)

AndreyS Scherbakov
  • 2,674
  • 2
  • 20
  • 27
0

you can use in eclipse a regex based find/replace,

if you search by

LOG(.*?)\((.*?)\)

and replace to

LOG\1 << \2

this will find all levels in the log like debug, info warning error etc

LOGD("DEBUG:hello");
LOGW("WARNING:World"); 
LOGE("ERROR:Fooo"); 
LOGI("INFO:Fooo); 

and will replace it to

LOGD << "DEBUG:hello";
LOGW << "WARNING:World"; 
LOGE << "ERROR:Fooo"; 
LOGI << "INFO:Fooo; 

enter image description here

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97