Author Topic: Advanced find and replace  (Read 652 times)

Offline Jewest

  • Multiple posting newcomer
  • *
  • Posts: 24
Advanced find and replace
« on: May 07, 2018, 11:16:08 am »
Hi,

I am using the vera++ checker and one of the remarks is that I use the short form for checking empty.
So far no problem, but I think the checker is right and I want to change the code.

so I want the change: if(!largertext.empty()) to: if(largertext.empty() == false)

any way to do this with the find and replace function?
If so how?

thank you in advance,

Jewest

Offline sodev

  • Almost regular
  • **
  • Posts: 178
Re: Advanced find and replace
« Reply #1 on: May 07, 2018, 01:07:39 pm »
Could be done with a regular expression, but i see no reason for. Actually the first form looks much more "correct" to me than the second one, especially in the c++ world where you use implicit conversions to bool the second one might even not work. Are you sure the checker complains about that? And are you sure that you are not using some strict c rules (i assume your code is c++)?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2105
Re: Advanced find and replace
« Reply #2 on: May 09, 2018, 12:36:49 am »
Do you want to do this only for one variable name, or for a lot different variable names?

Offline Jewest

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: Advanced find and replace
« Reply #3 on: June 05, 2018, 01:24:34 pm »
First up, sorry for the late reply. been busy using C::B to finish a project.

@Sodev: it is not an implicit convertion, !<statement> is. the return value of the function is a boolean.
@ BlueHazzard: Yes I would like to do this with different var names, otherwise a simple find and replace would due. but the vera++ is reporting about 100 times the same message.

Offline Jewest

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: Advanced find and replace
« Reply #4 on: December 04, 2018, 11:09:06 am »
any suggestions?
How do I use the regexp to fix this?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11277
    • Travis build status
Re: Advanced find and replace
« Reply #5 on: December 04, 2018, 11:16:37 am »
Probably you'll fail badly if you use regexps. The best option at the moment is to write a clang-tidy check and fixups. Or see if there isn't one already.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline sodev

  • Almost regular
  • **
  • Posts: 178
Re: Advanced find and replace
« Reply #6 on: December 04, 2018, 06:32:58 pm »
Depends on how well you keep your if's structured :).

The following expression does work with the CodeBlocks RegExp flavor and matches the presented format, it does allow extra whitespace where possible but it does not work with additional conditions nor if the if is spread across multiple lines nor if you use fancy unicode names for your identifiers (or anything else than 7-Bit ASCII).

Code: [Select]
Search: \([ \t]*if[ \t]*(\)[ \t]*![ \t]*\([a-zA-Z0-9_]+\.empty()\)[ \t]*\().*\)
Replace: \1\2 == false\3