-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_occurences.py
More file actions
29 lines (22 loc) · 1014 Bytes
/
replace_occurences.py
File metadata and controls
29 lines (22 loc) · 1014 Bytes
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
import os
import re
def replace_std_vector_in_file(filepath):
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# Regex pattern to match std::vector exactly (not part of bigger word)
pattern = r'\bsize_t\b'
new_content, count = re.subn(pattern, 'std::size_t', content)
if count > 0:
print(f"Replaced {count} occurrences in {filepath}")
with open(filepath, 'w', encoding='utf-8') as f:
f.write(new_content)
def replace_in_project(root_dir):
for dirpath, dirnames, filenames in os.walk(root_dir):
for filename in filenames:
# You can restrict to certain file extensions if needed
if filename.endswith(('.cpp', '.hpp', '.h', '.c', '.cc', '.cxx', '.cppm')):
filepath = os.path.join(dirpath, filename)
replace_std_vector_in_file(filepath)
if __name__ == "__main__":
project_root = '.' # Change if your project root is different
replace_in_project(project_root)