Created
December 14, 2015 10:50
-
-
Save dfroger/15a8d0fe5a1320ae673b to your computer and use it in GitHub Desktop.
Change coding rules for C++ class member from variable_ to m_variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
In all files passed in argument, change coding rules for C++ class member from | |
variable_ to m_variable. | |
""" | |
import sys | |
import re | |
def main(): | |
pattern = re.compile(r'(\b\w+)_\b') | |
for fp in sys.argv[1:]: | |
# Read file. | |
string = open(fp).read() | |
# Replace variable_ with m_variable | |
new_string, number_of_subs_made = re.subn(pattern, r'm_\1', string) | |
# Write new file. | |
with open(fp,'w') as f: | |
f.write(new_string) | |
# Report changes. | |
if number_of_subs_made: | |
print(fp, number_of_subs_made) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment