Skip to content

lalvarezt/string_pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”— String Pipeline

Crates.io Docs.rs CI License

A string transformation library and CLI tool for Rust. Chain operations like split, join, replace, and filter using template syntax.


πŸ“‹ Table of Contents

🌟 Why String Pipeline?

Transform complex text processing into simple, readable templates:

# Traditional approach (multiple commands) echo "john.doe@email.com,jane.smith@company.org" | \ tr ',' '\n' | \ grep -o '@[^,]*' | \ tr -d '@' | \ sort | \ tr '\n' ',' # String Pipeline (single template) string-pipeline "{split:,:..|map:{regex_extract:@(.+):1}|sort}" "john.doe@email.com,jane.smith@company.org" # Output: "company.org,email.com"

✨ Key Features

  • πŸ”— Chainable Operations: Pipe operations together naturally
  • πŸ—ΊοΈ Powerful Mapping: Apply sub-pipelines to each list item
  • πŸ” Regex Support: sed-like patterns for complex transformations
  • πŸ› Debug Mode: Step-by-step operation visualization

⚑ Examples

πŸ”₯ Basic Transformations

# Extract middle items from list string-pipeline "{split:,:1..3}" "a,b,c,d,e" # Output: "b,c" # Clean and format names string-pipeline '{split:,:..|map:{trim|upper|append:!}}' " john , jane , bob " # Output: "JOHN!,JANE!,BOB!" # Extract numbers and pad with zeros string-pipeline '{split:,:..|map:{regex_extract:\d+|pad:3:0:left}}' "item1,thing22,stuff333" # Output: "001,022,333"

🧠 Advanced Processing

# Filter files, format as list string-pipeline '{split:,:..|filter:\.py$|sort|map:{prepend:β€’ }|join:\n}' "app.py,readme.md,test.py,data.json" # Output: "β€’ app.py\nβ€’ test.py" # Extract domains from URLs string-pipeline '{split:,:..|map:{regex_extract://([^/]+):1|upper}}' "https://github.com,https://google.com" # Output: "GITHUB.COM,GOOGLE.COM" # Debug complex processing string-pipeline "{split: :..|filter:^[A-Z]|sort:desc}" "apple Banana cherry Date" # Output: Date,Banana

πŸš€ Installation

πŸ“¦ CLI Tool

# Install from crates.io cargo install string_pipeline # Or build from source git clone https://github.com/lalvarezt/string_pipeline.git cd string_pipeline cargo install --path .

πŸ“š Rust Library

Add to your Cargo.toml:

[dependencies] string_pipeline = "0.12.0"

πŸƒ Quick Start

πŸ’» CLI Usage

# With argument string-pipeline '{template}' "input string" # With stdin echo "input" | string-pipeline '{template}' # Debug mode string-pipeline --debug "{split:,:..|map:{upper}}" "hello,world" # DEBUG: πŸ“‚ MULTI-TEMPLATE # DEBUG: β”œβ”€β”€ 🏁 MULTI-TEMPLATE START # DEBUG: β”œβ”€β”€ Template: "{!split:,:..|map:{upper}}" # DEBUG: β”œβ”€β”€ ➑️ Input: "hello,world" # DEBUG: β”œβ”€β”€ 1 sections to process (literal: 0, template: 1) # DEBUG: β”‚ # DEBUG: β”œβ”€β”€ πŸ“Š SECTION 1/1: [template: split(',',..) | map { operations: [upper] }] # DEBUG: β”œβ”€β”€ πŸ’Ύ CACHE MISS Computing and storing result # DEBUG: β”‚ # DEBUG: β”œβ”€β”€ πŸ“‚ Main Pipeline # DEBUG: β”‚ β”œβ”€β”€ πŸš€ PIPELINE START: 2 operations # DEBUG: β”‚ β”œβ”€β”€ ➑️ Input: String(hello,world) # DEBUG: β”‚ β”œβ”€β”€ 1. Split(',') # DEBUG: β”‚ β”œβ”€β”€ 2. Map(1) # DEBUG: β”‚ β”œβ”€β”€ βš™οΈ Step 1: Split # DEBUG: β”‚ β”‚ β”œβ”€β”€ ➑️ Input: String(hello,world) # DEBUG: β”‚ β”‚ β”œβ”€β”€ 🎯 Result: List["hello", "world"] # DEBUG: β”‚ β”‚ └── Time: 332.41Β΅s # DEBUG: β”‚ β”œβ”€β”€ βš™οΈ Step 2: Map # DEBUG: β”‚ β”‚ β”œβ”€β”€ ➑️ Input: List["hello", "world"] # DEBUG: β”‚ β”‚ β”œβ”€β”€ 🎯 Result: String(processing...) # DEBUG: β”‚ β”‚ └── Time: 0ns # DEBUG: β”‚ β”‚ β”œβ”€β”€ πŸ—‚οΈ Item 1/2 # DEBUG: β”‚ β”‚ β”‚ β”œβ”€β”€ ➑️ Input: "hello" # DEBUG: β”‚ β”‚ β”‚ β”œβ”€β”€ πŸ“‚ Sub-Pipeline # DEBUG: β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ πŸ”§ SUB-PIPELINE START: 1 operations # DEBUG: β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ ➑️ Input: String(hello) # DEBUG: β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ βš™οΈ Step 1: Upper # DEBUG: β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ ➑️ Input: String(hello) # DEBUG: β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ 🎯 Result: String(HELLO) # DEBUG: β”‚ β”‚ β”‚ β”‚ β”‚ └── Time: 875ns # DEBUG: β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ βœ… SUB-PIPELINE COMPLETE # DEBUG: β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ 🎯 Result: String(HELLO) # DEBUG: β”‚ β”‚ β”‚ β”‚ └── Time: 16.37Β΅s # DEBUG: β”‚ β”‚ β”‚ └── Output: "HELLO" # DEBUG: β”‚ β”‚ β”œβ”€β”€ πŸ—‚οΈ Item 2/2 # DEBUG: β”‚ β”‚ β”‚ β”œβ”€β”€ ➑️ Input: "world" # DEBUG: β”‚ β”‚ β”‚ β”œβ”€β”€ πŸ“‚ Sub-Pipeline # DEBUG: β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ πŸ”§ SUB-PIPELINE START: 1 operations # DEBUG: β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ ➑️ Input: String(world) # DEBUG: β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ βš™οΈ Step 1: Upper # DEBUG: β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ ➑️ Input: String(world) # DEBUG: β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ 🎯 Result: String(WORLD) # DEBUG: β”‚ β”‚ β”‚ β”‚ β”‚ └── Time: 93ns # DEBUG: β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ βœ… SUB-PIPELINE COMPLETE # DEBUG: β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ 🎯 Result: String(WORLD) # DEBUG: β”‚ β”‚ β”‚ β”‚ └── Time: 15.749Β΅s # DEBUG: β”‚ β”‚ β”‚ └── Output: "WORLD" # DEBUG: β”‚ β”‚ └── πŸ“¦ MAP COMPLETED: 2 β†’ 2 items # DEBUG: β”‚ β”œβ”€β”€ βœ… PIPELINE COMPLETE # DEBUG: β”‚ β”œβ”€β”€ 🎯 Result: List["HELLO", "WORLD"] # DEBUG: β”‚ └── Time: 457.193Β΅s # DEBUG: β”‚ # DEBUG: β”œβ”€β”€ 🏁 βœ… MULTI-TEMPLATE COMPLETE # DEBUG: β”œβ”€β”€ 🎯 Final result: "HELLO,WORLD" # DEBUG: β”œβ”€β”€ Total execution time: 568.533Β΅s # DEBUG: └── Cache stats: 0 regex patterns, 1 split operations cached # HELLO,WORLD

πŸ¦€ Library Usage

use string_pipeline::Template; fn main() -> Result<(), Box<dyn std::error::Error>> { let template = Template::parse("{split:,:..|map:{upper}|join:-}")?; let result = template.format("hello,world,rust")?; println!("{}", result); // "HELLO-WORLD-RUST" Ok(()) }

πŸ§ͺ Testing

# Run all tests cargo test # Run with output cargo test -- --nocapture # Run benchmarks cargo bench

⚑ Performance & Benchmarking

String Pipeline includes simple benchmarking tools for measuring performance:

# Build the benchmark tool cargo build --release --bin bench # Run benchmarks (1000 iterations) ./target/release/bench # Quick performance check (100 iterations) ./target/release/bench --iterations 100 # Generate JSON for scripts ./target/release/bench --format json > benchmark_results.json

πŸ“š Documentation

πŸ“– Template System βš™οΈ CLI Options & Usage πŸ” Comprehensive Debug System Guide πŸ“Š Performance Benchmarking Guide

🀝 Contributing

We welcome contributions! πŸŽ‰

  • πŸ› Report bugs via GitHub Issues
  • πŸ’‘ Suggest features or improvements
  • πŸ”§ Submit pull requests

πŸ“„ License

This project is licensed under the MIT License. See LICENSE for details.


⚑ Fast and composable string transformations made simple!

About

Powerful CLI tool and Rust library for chainable string transformations using intuitive template syntax πŸ”—

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages