mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
type: ignore[codes]
and knot: ignore
(#15078)
This commit is contained in:
parent
9eb73cb7e0
commit
2f85749fa0
13 changed files with 737 additions and 48 deletions
|
@ -56,10 +56,8 @@ impl<'a> Cursor<'a> {
|
|||
self.chars.clone().next_back().unwrap_or(EOF_CHAR)
|
||||
}
|
||||
|
||||
// SAFETY: The `source.text_len` call in `new` would panic if the string length is larger than a `u32`.
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
pub fn text_len(&self) -> TextSize {
|
||||
TextSize::new(self.chars.as_str().len() as u32)
|
||||
self.chars.as_str().text_len()
|
||||
}
|
||||
|
||||
pub fn token_len(&self) -> TextSize {
|
||||
|
@ -103,6 +101,16 @@ impl<'a> Cursor<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Eats the next character if `predicate` returns `true`.
|
||||
pub fn eat_if(&mut self, mut predicate: impl FnMut(char) -> bool) -> bool {
|
||||
if predicate(self.first()) && !self.is_eof() {
|
||||
self.bump();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Eats symbols while predicate returns true or until the end of file is reached.
|
||||
pub fn eat_while(&mut self, mut predicate: impl FnMut(char) -> bool) {
|
||||
// It was tried making optimized version of this for eg. line comments, but
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue