Removes lines containing only blank characters before and after the text. Args: lines: A list of lines. Returns: A list of lines without trailing or leading blank lines.
(lines)
| 209 | |
| 210 | |
| 211 | def _strip_blank_lines(lines): |
| 212 | """Removes lines containing only blank characters before and after the text. |
| 213 | |
| 214 | Args: |
| 215 | lines: A list of lines. |
| 216 | Returns: |
| 217 | A list of lines without trailing or leading blank lines. |
| 218 | """ |
| 219 | # Find the first non-blank line. |
| 220 | start = 0 |
| 221 | num_lines = len(lines) |
| 222 | while lines and start < num_lines and _is_blank(lines[start]): |
| 223 | start += 1 |
| 224 | |
| 225 | lines = lines[start:] |
| 226 | |
| 227 | # Remove trailing blank lines. |
| 228 | while lines and _is_blank(lines[-1]): |
| 229 | lines.pop() |
| 230 | |
| 231 | return lines |
| 232 | |
| 233 | |
| 234 | def _is_blank(line): |