Jump to content
  • Advertisement
Sign in to follow this  
gabrielauditore

Visual Studio: regex find replace

This topic is 2516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys i'm trying to write a regex query for vs2008 that will convert
m_pPointer->m_nVariable
to
(*m_pPointer).m_nVariable

I can do that no problem, but the codebase i'm in has some nested / cryptic shit
variable.p_subvar->x[y]->w[q].newvar->damn
in which case i hope to run the query and convert it to
(*(variable.p_subvar->x[y]->w[q].newvar)).damn

This is my search query so far:
{((:i)(\[:i\})*(.|-\>)*)*:i}-\>{:i}
However it qualifies a whole line for some reason :(
Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
To me, what you're trying to do would be obfuscating the code. -> is right next to the member it operates on, making it understandable without disentangling any nested parentheses.

Speaking for the person who's going to maintain this code-base after you: please don't do this.

Share this post


Link to post
Share on other sites
The code base will die once the product is shipped; no further updates will be made. BUT, the -> operator seems to be causing some slow downs in performance heavy areas of code (I don't know if it's just not optimal code generation or cache hit misses or what). Basically the final thing before the "game" ships will be to replace all -> with explicit dereferences but it's turning out to be quite a challenge to do so.

Share this post


Link to post
Share on other sites
It's not very clear to me why this sort of change would help solve your problems. Nevertheless, can you not just do this until there are 0 matches?
Find: {[^ ]*}\-\>{.*}
Replace: (*\1).\2

A 100% perfect general solution is tough, but a 95% solution that requires a few manual tweaks after might be much easier.

Share this post


Link to post
Share on other sites
You do realize that foo->bar and (*foo).bar are going to compile to the exact same code, barring a fantastically bad compiler... right?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!