-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathchange.py
41 lines (33 loc) · 1.09 KB
/
change.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import re
import sys
if __name__ == "__main__":
regexpr = re.compile('\\bm(\\w+)\\b')
fileName = sys.argv[1]
content = None
with open(fileName,'r') as fr:
content = fr.read()
it = regexpr.finditer(content)
match = None
try:
match = it.next()
except StopIteration :
print >>sys.stderr,"not found"
pass
if match:
print >>sys.stderr,"found matching"
with open(fileName,'w') as fw:
start = 0
try:
while True:
group1 = match.group(1)
if group1[0].islower():
match = it.next()
continue
fw.write(content[start:match.start()])
print >>sys.stderr,"replacing {0},at {1}".format(group1,match.start())
fw.write('m_' + group1[0].lower() + group1[1:])
start = match.end()
match = it.next()
except StopIteration:
pass
fw.write(content[start:])