I have a complete Java based code base, where members are named:
String m_sFoo;
Array m_arrKeepThings;
Variable/object names includes both a m_ prefix to indicate a member, and an hungarian notation type indicator.
I'm looking for a way to perform a single time code replacment to (for example on the above to cases):
Array keepThings;
String foo;
Of course there are many other alternatives, but I hope that based on two examples, I'll be able to perform the full change. Performances is not an issue as it's a single time fix.
To clarify, if I had to explain this in lines, it would be:
Check out this post: Regex to change to sentence case
Generally I am afraid that you cannot change the case of letters using regular expressions.
I'd recommend you to implement a simple utility (using any language you want). You can do it in java. Just go through your file tree, search for pattern like m_[sidc]([A-Z]), take the captured sequence, call toLowerCase() and perform replace.
Other solution is to search and replace for m_sA, then m_sB, ... m_sZ using eclipse. Total: 26 times. It is a little bit stupid but probably anyway faster than implementing and debugging of your own code.
If you are really, really sure that the proposed changed won't result in clashes (variables that only differ in their prefix) I would do it with a line of perl:
perl -pi.bak -e "s/\bm_[a-z_]+([A-Z]\w*)\b/this.\u$1/g;" *.java
This will perform an inline edit of your Java sources, while keeping a backup with extension .bak replacing your pattern between word boundaries (\b) capitalising the first letter of the replacement (\u) multiple times per line.
You can then perform a diff between the backup files and the result files to see if all went well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With