Extract all SEARCH/REPLACE diff blocks from a given text. Args: diff_text: The text containing diff blocks. diff_pattern: The regex pattern for the SEARCH/REPLACE format. Returns: A list of tuples, where each tuple is (search_text, replace_text).
(
diff_text: str, diff_pattern: str = r"<<<<<<< SEARCH\n(.*?)=======\n(.*?)>>>>>>> REPLACE"
)
| 88 | |
| 89 | |
| 90 | def extract_diffs( |
| 91 | diff_text: str, diff_pattern: str = r"<<<<<<< SEARCH\n(.*?)=======\n(.*?)>>>>>>> REPLACE" |
| 92 | ) -> List[Tuple[str, str]]: |
| 93 | """ |
| 94 | Extract all SEARCH/REPLACE diff blocks from a given text. |
| 95 | |
| 96 | Args: |
| 97 | diff_text: The text containing diff blocks. |
| 98 | diff_pattern: The regex pattern for the SEARCH/REPLACE format. |
| 99 | |
| 100 | Returns: |
| 101 | A list of tuples, where each tuple is (search_text, replace_text). |
| 102 | """ |
| 103 | # Use re.findall with DOTALL flag to match across multiple lines |
| 104 | diff_blocks = re.findall(diff_pattern, diff_text, re.DOTALL) |
| 105 | # Strip trailing whitespace from both search and replace parts for clean matching |
| 106 | return [(match[0].rstrip(), match[1].rstrip()) for match in diff_blocks] |
| 107 | |
| 108 | |
| 109 | def parse_full_rewrite(llm_response: str, language: str = "python") -> Optional[str]: |
no outgoing calls
no test coverage detected