perl-lexer 0.15.0

High-performance Perl lexer with context-aware tokenization
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::sync::{Arc, OnceLock};

// Pre-allocated empty Arc to avoid repeated allocations.
static EMPTY_ARC: OnceLock<Arc<str>> = OnceLock::new();

#[inline(always)]
pub(crate) fn empty_arc() -> Arc<str> {
    EMPTY_ARC.get_or_init(|| Arc::from("")).clone()
}

pub(crate) fn truncate_preview(text: &str, max_chars: usize) -> String {
    match text.char_indices().nth(max_chars) {
        Some((idx, _)) => format!("{}...", &text[..idx]),
        None => text.to_string(),
    }
}