replace the text surrounded by "label start" and "label end" to new_code :param file: the .cpp or .h file :param label: the label surrounds the text to be replaced
(file: str, label: str, reformat: bool=True)
| 190 | |
| 191 | |
| 192 | def update_code(file: str, label: str, reformat: bool=True) -> None: |
| 193 | """ |
| 194 | replace the text surrounded by "label start" and "label end" to new_code |
| 195 | :param file: the .cpp or .h file |
| 196 | :param label: the label surrounds the text to be replaced |
| 197 | """ |
| 198 | global str_io |
| 199 | with open(file, 'r') as f: |
| 200 | s = f.read() |
| 201 | start = '// {} start\n'.format(label) |
| 202 | idx1 = s.find(start) + len(start) |
| 203 | end = '// {} end'.format(label) |
| 204 | idx2 = s.find(end) |
| 205 | assert start in s and end in s |
| 206 | with open(file, 'w') as f: |
| 207 | new_s = s[:idx1] + str_io.getvalue() + s[idx2:] |
| 208 | f.write(new_s) |
| 209 | str_io = io.StringIO() |
| 210 | if reformat: |
| 211 | clang_format(file) |
| 212 | |
| 213 | |
| 214 | def generate_onnx_converter(): |
no test coverage detected