Expand description
§strs_tools
Advanced string manipulation tools with SIMD acceleration and intelligent parsing.
§Why strs_tools?
While Rust’s standard library provides basic string operations, strs_tools
offers sophisticated string manipulation capabilities that handle real-world complexity:
- Smart Splitting: Split strings with quote awareness, escape handling, and delimiter preservation
- Intelligent Parsing: Parse command-like strings and extract key-value parameters
- Fast Performance: Optional SIMD acceleration for high-throughput text processing
- Memory Efficient: Zero-allocation operations where possible using
Cow<str>
§Quick Start
cargo add strs_tools
§Examples
§Advanced String Splitting
Unlike standard str.split()
, handles quotes and preserves context:
use strs_tools::string;
// Basic splitting with delimiter preservation
let text = "hello world test";
let result : Vec< String > = string::split()
.src( text )
.delimeter( " " )
.stripping( false ) // Keep delimiters
.perform()
.map( String::from )
.collect();
assert_eq!( result, vec![ "hello", " ", "world", " ", "test" ] );
// Quote-aware splitting (perfect for parsing commands)
let command = r#"run --file "my file.txt" --verbose"#;
let parts : Vec< String > = string::split()
.src( command )
.delimeter( " " )
.quoting( true ) // Handle quotes intelligently
.perform()
.map( String::from )
.collect();
// Results: ["run", "--file", "my file.txt", "--verbose"]
§Text Indentation
Add consistent indentation to multi-line text:
use strs_tools::string;
let code = "fn main() {\n println!(\"Hello\");\n}";
let indented = string::indentation::indentation( " ", code, "" );
// Result: " fn main() {\n println!(\"Hello\");\n }"
§Command Parsing
Parse command-line style strings into structured data:
use strs_tools::string;
let input = "deploy --env production --force --config ./deploy.toml";
// Command parsing functionality under development
println!( "Command: {}", input );
// Note: Full parse_request API is still being finalized
§Number Parsing
Robust number parsing with multiple format support:
let values = [ "42", "3.14", "1e6" ];
for val in values
{
if let Ok( num ) = val.parse::< f64 >()
{
println!( "{} = {}", val, num );
}
}
§Performance Features
Enable SIMD acceleration for demanding applications:
[dependencies]
strs_tools = { version = "0.24", features = ["simd"] }
SIMD features provide significant speedups for:
- Large text processing
- Pattern matching across multiple delimiters
- Bulk string operations
§Feature Selection
Choose only the functionality you need:
[dependencies]
strs_tools = {
version = "0.24",
features = ["string_split", "string_parse_request"],
default-features = false
}
Available features:
string_split
- Advanced splitting with quotes and escapingstring_indentation
- Text indentation toolsstring_isolate
- String isolation by delimitersstring_parse_request
- Command parsing utilitiesstring_parse_number
- Number parsing from stringssimd
- SIMD acceleration (recommended for performance)
§When to Use strs_tools
Perfect for:
- CLI applications parsing complex commands
- Configuration file processors
- Text processing tools and parsers
- Data extraction from formatted text
- Applications requiring high-performance string operations
Alternatives:
- Use standard
str
methods for simple splitting and basic operations - Consider
regex
crate for complex pattern matching - Use
clap
orstructopt
for full CLI argument parsing frameworks
§Examples
Explore comprehensive examples showing real-world usage:
git clone https://github.com/Wandalen/wTools
cd wTools/module/core/strs_tools
# Run examples by number
cargo run --example 001_basic_usage
cargo run --example 002_advanced_splitting
cargo run --example 003_text_indentation
cargo run --example 004_command_parsing
cargo run --example 005_string_isolation
cargo run --example 006_number_parsing
cargo run --example 007_performance_and_simd --features simd
§Documentation
§Rule Compliance & Architectural Notes
This crate has been systematically updated to comply with the Design and Codestyle Rulebooks. Key compliance achievements and ongoing considerations:
§Completed Compliance Work:
-
Documentation Strategy: Uses
#![ doc = include_str!(...) ]
to include readme.md instead of duplicating documentation. This is the mandated approach for all entry files. -
Workspace Dependencies: All external dependencies now inherit from workspace with
{ workspace = true }
. SIMD optimization deps (memchr, aho-corasick, bytecount, lexical) were moved to workspace level for version consistency. -
Attribute Formatting: All attributes use proper spacing per Universal Formatting Rule:
#[ cfg( feature = "enabled" ) ]
instead of#[ cfg( feature = "enabled" ) ]
-
mod_interface Architecture: Converted from manual namespace patterns to
mod_interface!
macro usage for cleaner module organization and controlled visibility.
§Critical Architectural Decisions:
-
Feature Gating: All functionality is gated behind the “enabled” feature, which now also enables “mod_interface/enabled” for proper macro functionality.
-
Error Handling: Uses
error_tools
exclusively - noanyhow
orthiserror
dependencies per Design Rulebook requirements. -
Testing Isolation: All tests are in
tests/
directory, never insrc/
, following the mandatory testing architecture pattern.