#![deny(unsafe_code)]
#![warn(rust_2018_idioms)]
#![warn(missing_docs)]
#![warn(clippy::all)]
#[must_use]
pub fn line_bounds_at(text: &str, cursor_pos: usize) -> (usize, usize) {
let cursor = cursor_pos.min(text.len());
let start = text[..cursor].rfind('\n').map_or(0, |idx| idx + 1);
let end = text[cursor..].find('\n').map_or(text.len(), |idx| cursor + idx);
(start, end)
}
#[must_use]
pub fn is_identifier_byte(byte: u8) -> bool {
byte.is_ascii_alphanumeric() || byte == b'_'
}
#[must_use]
pub fn is_keyword_boundary(bytes: &[u8], start: usize, len: usize) -> bool {
if start > bytes.len() {
return false;
}
let end = start.saturating_add(len);
if end > bytes.len() {
return false;
}
if start > 0 && is_identifier_byte(bytes[start - 1]) {
return false;
}
if end < bytes.len() && is_identifier_byte(bytes[end]) {
return false;
}
true
}
#[must_use]
pub fn skip_ascii_whitespace(bytes: &[u8], mut idx: usize) -> usize {
while idx < bytes.len() && bytes[idx].is_ascii_whitespace() {
idx += 1;
}
idx
}