Crates.io | rreplace |
lib.rs | rreplace |
version | 0.1.5 |
source | src |
created_at | 2019-08-27 22:43:43.898712 |
updated_at | 2019-08-28 18:53:52.019445 |
description | String replacement made easy! It can handle multiple unique replacements in one pass. |
homepage | |
repository | https://github.com/bcopp/rreplace |
max_upload_size | |
id | 160238 |
size | 19,081 |
rreplace is a rust library designed to streamline string replacements. It can handle multiple unique replacements and iterates the string only once. Repacements may eclipse one another, therefore rreplace follows this priority.
// Create HashMap to define replacements
let replace: Hashmap<&str, &str> = Hashmap::new();
replace.insert("This", "xxxx");
replace.insert("foo", "foobar");
rreplace::run("This string is foo", r);
// Returns: "xxxx string is foobar"
replace.insert("This string", "xxx");
replace.insert("string", "yyy");
rreplace::run("This string is foo", r);
// Returns: "xxx is foo"
"This string"
begins matching before "string"
and therefore takes
replacement priority.
replace.insert("This string", "yyy");
replace.insert("This", "xxx");
rreplace::run("This string is foo", replace);
// Returns: "xxx is foo"
Both seqences begin matching on the same index, therefore the longer replacement takes priority.
replace.insert("string is foo", "yyy");
replace.insert("i", "I");
rreplace::run("This string is foo", replace);
// Returns: "ThIs xxx"
"i"
cannot be replaced within "string is foo"
. This is because
"string is foo"
begins matching earlier than the individual "i"
within.
replace.insert("string is X", "yyy");
replace.insert("i", "I");
rreplace::run("This string is foo", replace);
// Returns: "ThIs strIng Is foo"
"string is X"
is unable to find a complete match and therefore "i"
matches with every i
within the string.
I new to Rust and would love feedback on my code! Send me an email or contact me through my repository page.