Check whether the keyword at position `i` is preceded by `use ` (with optional whitespace), indicating a `use function` or `use const` import statement rather than a declaration.
(content: &[u8], i: usize)
| 1590 | /// (with optional whitespace), indicating a `use function` or `use const` |
| 1591 | /// import statement rather than a declaration. |
| 1592 | fn is_preceded_by_use(content: &[u8], i: usize) -> bool { |
| 1593 | if i < 4 { |
| 1594 | return false; |
| 1595 | } |
| 1596 | // Walk backwards over whitespace. |
| 1597 | let mut j = i - 1; |
| 1598 | while j > 0 && content[j].is_ascii_whitespace() { |
| 1599 | j -= 1; |
| 1600 | } |
| 1601 | // Check for `use` (the 'e' is at j, 'u' at j-2). |
| 1602 | if j >= 2 && &content[j - 2..=j] == b"use" { |
| 1603 | // Make sure `use` itself is at a keyword boundary (not part |
| 1604 | // of a longer identifier like `reuse`). |
| 1605 | if j - 2 == 0 || is_boundary_char(content[j - 3]) { |
| 1606 | return true; |
| 1607 | } |
| 1608 | } |
| 1609 | false |
| 1610 | } |
| 1611 | |
| 1612 | /// Check whether a keyword can start at this offset. |
| 1613 | /// |
no test coverage detected