Skip to content

Instantly share code, notes, and snippets.

@dfroger
Created December 14, 2015 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfroger/15a8d0fe5a1320ae673b to your computer and use it in GitHub Desktop.
Save dfroger/15a8d0fe5a1320ae673b to your computer and use it in GitHub Desktop.
Change coding rules for C++ class member from variable_ to m_variable
"""
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