Visual Studio: regex find replace

Started by
3 comments, last by ApochPiQ 12 years, 3 months ago
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?
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.
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.
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.
You do realize that foo->bar and (*foo).bar are going to compile to the exact same code, barring a fantastically bad compiler... right?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement