mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-01 16:17:33 +00:00
Move Python whitespace utilities into new ruff_python_whitespace
crate (#4993)
## Summary `ruff_newlines` becomes `ruff_python_whitespace`, and includes the existing "universal newline" handlers alongside the Python whitespace-specific utilities.
This commit is contained in:
parent
e86f12a1ec
commit
1d756dc3a7
57 changed files with 153 additions and 140 deletions
22
crates/ruff_python_ast/src/docstrings.rs
Normal file
22
crates/ruff_python_ast/src/docstrings.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
//! Utilities for parsing Python docstrings.
|
||||
|
||||
/// Extract the leading words from a line of text within a Python docstring.
|
||||
pub fn leading_words(line: &str) -> &str {
|
||||
let line = line.trim();
|
||||
line.find(|char: char| !char.is_alphanumeric() && !char.is_whitespace())
|
||||
.map_or(line, |index| &line[..index])
|
||||
}
|
||||
|
||||
/// Extract the leading whitespace from a line of text within a Python docstring.
|
||||
pub fn leading_space(line: &str) -> &str {
|
||||
line.find(|char: char| !char.is_whitespace())
|
||||
.map_or(line, |index| &line[..index])
|
||||
}
|
||||
|
||||
/// Replace any non-whitespace characters from an indentation string within a Python docstring.
|
||||
pub fn clean_space(indentation: &str) -> String {
|
||||
indentation
|
||||
.chars()
|
||||
.map(|char| if char.is_whitespace() { char } else { ' ' })
|
||||
.collect()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue