Replace `code` by a pattern of the form `with X1->X2,Y1->Y2,Z1->Z2`. Args: code (`str`): The code to be modified. replace_pattern (`str`): The pattern used to modify `code`. Returns: `str`: The modified code.
(code: str, replace_pattern: str)
| 471 | |
| 472 | |
| 473 | def replace_code(code: str, replace_pattern: str) -> str: |
| 474 | """Replace `code` by a pattern of the form `with X1->X2,Y1->Y2,Z1->Z2`. |
| 475 | |
| 476 | Args: |
| 477 | code (`str`): The code to be modified. |
| 478 | replace_pattern (`str`): The pattern used to modify `code`. |
| 479 | |
| 480 | Returns: |
| 481 | `str`: The modified code. |
| 482 | """ |
| 483 | if len(replace_pattern) > 0: |
| 484 | patterns = replace_pattern.replace("with", "").split(",") |
| 485 | patterns = [_re_replace_pattern.search(p) for p in patterns] |
| 486 | for pattern in patterns: |
| 487 | if pattern is None: |
| 488 | continue |
| 489 | obj1, obj2, option = pattern.groups() |
| 490 | code = re.sub(obj1, obj2, code) |
| 491 | if option.strip() == "all-casing": |
| 492 | code = re.sub(obj1.lower(), obj2.lower(), code) |
| 493 | code = re.sub(obj1.upper(), obj2.upper(), code) |
| 494 | |
| 495 | return code |
| 496 | |
| 497 | |
| 498 | def find_code_and_splits(object_name: str, base_path: str, buffer: dict | None = None): |
no test coverage detected