Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
- Add new `sal-rhai` crate for Rhai scripting integration - Integrate Rhai with existing SAL modules - Improve error handling for Rhai scripts and SAL functions - Add comprehensive unit and integration tests for `sal-rhai`
60 lines
1.6 KiB
Rust
60 lines
1.6 KiB
Rust
//! SAL Text - Text processing and manipulation utilities
|
|
//!
|
|
//! This crate provides a comprehensive collection of text processing utilities including:
|
|
//! - **Text indentation**: Remove common leading whitespace (`dedent`) and add prefixes (`prefix`)
|
|
//! - **String normalization**: Sanitize strings for filenames (`name_fix`) and paths (`path_fix`)
|
|
//! - **Text replacement**: Powerful `TextReplacer` for regex and literal replacements
|
|
//! - **Template rendering**: `TemplateBuilder` using Tera engine for dynamic text generation
|
|
//!
|
|
//! All functionality is available in both Rust and Rhai scripting environments.
|
|
//!
|
|
//! # Examples
|
|
//!
|
|
//! ## Text Indentation
|
|
//!
|
|
//! ```rust
|
|
//! use sal_text::dedent;
|
|
//!
|
|
//! let indented = " line 1\n line 2\n line 3";
|
|
//! let dedented = dedent(indented);
|
|
//! assert_eq!(dedented, "line 1\nline 2\n line 3");
|
|
//! ```
|
|
//!
|
|
//! ## String Normalization
|
|
//!
|
|
//! ```rust
|
|
//! use sal_text::name_fix;
|
|
//!
|
|
//! let unsafe_name = "User's File [Draft].txt";
|
|
//! let safe_name = name_fix(unsafe_name);
|
|
//! assert_eq!(safe_name, "user_s_file_draft_.txt");
|
|
//! ```
|
|
//!
|
|
//! ## Text Replacement
|
|
//!
|
|
//! ```rust
|
|
//! use sal_text::TextReplacer;
|
|
//!
|
|
//! let replacer = TextReplacer::builder()
|
|
//! .pattern(r"\d+")
|
|
//! .replacement("NUMBER")
|
|
//! .regex(true)
|
|
//! .build()
|
|
//! .expect("Failed to build replacer");
|
|
//!
|
|
//! let result = replacer.replace("There are 123 items");
|
|
//! assert_eq!(result, "There are NUMBER items");
|
|
//! ```
|
|
|
|
mod dedent;
|
|
mod fix;
|
|
mod replace;
|
|
mod template;
|
|
|
|
pub mod rhai;
|
|
|
|
pub use dedent::*;
|
|
pub use fix::*;
|
|
pub use replace::*;
|
|
pub use template::*;
|