I have a large codebase to sort through, so I’d like to automate the process as much as possible. I’ve already managed to grep out all the lines that are relevant to my task, but I’d like to automate the task itself.
What I’m trying to do is change all trailing increments to leading increments, as in the following example:
i++;
becomes
++i;
I imagine that regexes will be involved, and I’m rather rusty with those. Also, which language would be best for scripting this? I’m working on Windows 7 x64 at the moment, but a platform-agnostic solution would be cool. Also, if you could point me to any specific resources for learning more about this type of problem, that would be awesome.
This would do it…
But it’s evil, and will break things like:
Not to mention the cases where i++ and ++i actually do different things, and you need to use i++.
My suggestion (assuming you actually have some real reason to think that i++ is wrong in many cases):
Then open
fixme.txtin your favorite text editor, and manually investigate each occurrence, removing it from the text file as you go.