Return common prefix for a list of lines. This will ignore lines that contain whitespace only.
(strings: Iterable[str])
| 192 | |
| 193 | |
| 194 | def _common_whitespace_prefix(strings: Iterable[str]) -> str: |
| 195 | """ |
| 196 | Return common prefix for a list of lines. |
| 197 | This will ignore lines that contain whitespace only. |
| 198 | """ |
| 199 | # Ignore empty lines and lines that have whitespace only. |
| 200 | strings = [s for s in strings if not s.isspace() and not len(s) == 0] |
| 201 | |
| 202 | if not strings: |
| 203 | return "" |
| 204 | |
| 205 | else: |
| 206 | s1 = min(strings) |
| 207 | s2 = max(strings) |
| 208 | |
| 209 | for i, c in enumerate(s1): |
| 210 | if c != s2[i] or c not in " \t": |
| 211 | return s1[:i] |
| 212 | |
| 213 | return s1 |