module documentation
Git stripspace functionality for cleaning up text and commit messages.
| Function | stripspace |
Strip unnecessary whitespace from text. |
def stripspace(text:
bytes, *, strip_comments: bool = False, comment_char: bytes = b'#', comment_lines: bool = False) -> bytes:
ΒΆ
Strip unnecessary whitespace from text.
This function mimics the behavior of git stripspace, which is commonly used to clean up commit messages and other text content.
- The function performs the following operations (in order):
- If comment_lines is True, prepend comment_char + space to each line
- Strip trailing whitespace from each line
- If strip_comments is True, remove lines starting with comment_char
- Collapse multiple consecutive blank lines into a single blank line
- Remove leading blank lines
- Remove trailing blank lines
- Ensure the text ends with a newline (unless empty)
| Parameters | |
text:bytes | The text to process (as bytes) |
stripbool | If True, remove lines that begin with comment_char |
commentbytes | The comment character to use (default: b"#") |
commentbool | If True, prepend comment_char to each line |
| Returns | |
bytes | The processed text as bytes |