grippo 0.3.1

Grok, regex, CEL and scrubbing on typed primitives. Up to 9 times faster than the stock Rust regex.
Documentation
// Project:   grippo
// File:      src/scrub/classes.rs
// Purpose:   Unicode classes the standard library has no test for, read from the regex engine
// Language:  Rust
//
// License:   Apache-2.0
// Copyright: (c) 2026 HYPERI PTY LIMITED

//! The decimal digits, the dashes and the combining marks, as sorted ranges
//! read once from the regex engine's own tables, so the scrub layers and the
//! patterns they match agree on what each class holds.

use regex_syntax::hir::{Class, HirKind};

/// The ranges of the Unicode class `pattern` names, sorted.
pub(super) fn class_ranges(pattern: &str) -> Vec<(u32, u32)> {
    let Ok(hir) = regex_syntax::parse(pattern) else {
        return Vec::new();
    };
    match hir.kind() {
        HirKind::Class(Class::Unicode(class)) => class
            .iter()
            .map(|r| (u32::from(r.start()), u32::from(r.end())))
            .collect(),
        _ => Vec::new(),
    }
}

/// The range of `ranges` holding `c`, if one does.
pub(super) fn range_of(ranges: &[(u32, u32)], c: char) -> Option<(u32, u32)> {
    let at = u32::from(c);
    let i = ranges.partition_point(|&(_, hi)| hi < at);
    ranges.get(i).copied().filter(|&(lo, _)| lo <= at)
}