Skip to main content

Crate sal_text

Crate sal_text 

Source
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 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

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§

ReplacementOperation
A single replacement operation with a pattern and replacement text
TemplateBuilder
A builder for creating and rendering templates using the Tera template engine.
TextReplacer
Text replacer that can perform multiple replacement operations in a single pass over the input text.
TextReplacerBuilder
Builder for the TextReplacer.

Enums§

ReplaceMode
Represents the type of replacement to perform.

Functions§

dedent
Dedent a multiline string by removing common leading whitespace.
name_fix
path_fix
prefix
Prefix a multiline string with a specified prefix.