Trims at most `indent_len` indentation from the beginning of `line`. This is useful when one needs to trim some minimum level of indentation from a code snippet collected from a docstring before attempting to reformat it.
(self, line: &str)
| 1817 | /// level of indentation from a code snippet collected from a docstring before |
| 1818 | /// attempting to reformat it. |
| 1819 | fn trim_start_str(self, line: &str) -> &str { |
| 1820 | let mut seen_indent_len = 0; |
| 1821 | let mut trimmed = line; |
| 1822 | let indent_len = self.columns(); |
| 1823 | |
| 1824 | for char in line.chars() { |
| 1825 | if seen_indent_len >= indent_len { |
| 1826 | return trimmed; |
| 1827 | } |
| 1828 | if char == '\t' { |
| 1829 | // Pad to the next multiple of tab_width |
| 1830 | seen_indent_len += tab_offset(seen_indent_len, Self::TAB_INDENT_WIDTH); |
| 1831 | trimmed = &trimmed[1..]; |
| 1832 | } else if char.is_whitespace() { |
| 1833 | seen_indent_len += char.len_utf8(); |
| 1834 | trimmed = &trimmed[char.len_utf8()..]; |
| 1835 | } else { |
| 1836 | break; |
| 1837 | } |
| 1838 | } |
| 1839 | trimmed |
| 1840 | } |
| 1841 | |
| 1842 | const fn is_spaces_tabs(self) -> bool { |
| 1843 | matches!(self, Self::SpacesTabs { .. }) |
no test coverage detected