Formatify
Formatify is a rust library designed for dynamic string formatting. It offers flexible and powerful tools for parsing strings with placeholders and replacing them with corresponding values. The library's key feature is its ability to handle various placeholder formats and alignment options.
Usage
Import the necessary modules and use Formatify for string formatting tasks:
use Formatify;
use HashMap;
Features
- Placeholder Replacement: Replace placeholders in strings with values from a
HashMap. - Length Measurement: Measure lengths of strings and placeholders.
- Placeholder Extraction: Extract placeholder keys from a string.
Examples
Replacing Placeholders
let mut key_value: = new;
key_value.insert;
let formatter = new;
let formatted_string = formatter.replace_placeholders;
assert_eq!;
Measuring Lengths
let segment_lengths = formatter.measure_lengths;
assert_eq!; // Total length with "Alice" as the placeholder, length of "Alice"
Extracting Placeholder Keys
let placeholder_keys = formatter.extract_placeholder_keys;
assert_eq!;
Testing
The library includes comprehensive tests for each functionality, ensuring reliability and correctness.
Conclusion
Formatify offers a versatile solution for dynamic string formatting in Rust, suitable for various applications requiring template-based string manipulation.