- Add a new crate `sal-text` for text manipulation utilities. - Integrate `sal-text` into the main `sal` crate. - Remove the previous `text` module from `sal`. This improves organization and allows for independent development of the `sal-text` library.
This commit is contained in:
59
text/src/lib.rs
Normal file
59
text/src/lib.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
//! 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, "users_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::*;
|
||||
Reference in New Issue
Block a user