Expand description
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
TextReplacerfor regex and literal replacements - Template rendering:
TemplateBuilderusing Tera engine for dynamic text generation
All functionality is available in both Rust and Rhai scripting environments.
§Examples
§Text Indentation
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
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
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");Modules§
- rhai
- Rhai wrappers for Text module functions
Structs§
- Replacement
Operation - A single replacement operation with a pattern and replacement text
- Template
Builder - A builder for creating and rendering templates using the Tera template engine.
- Text
Replacer - Text replacer that can perform multiple replacement operations in a single pass over the input text.
- Text
Replacer Builder - Builder for the TextReplacer.
Enums§
- Replace
Mode - Represents the type of replacement to perform.