#str #lazy #escape #replace

lazy-transform-str

Lazy-copying lazy-allocated scanning str transformations. This is good e.g. for (un)escaping text, especially if individual strings are short.

6 releases

0.0.6 Sep 22, 2020
0.0.5 Sep 11, 2020
0.0.1 Aug 26, 2020

#118 in Text processing

Download history 10/week @ 2020-08-23 34/week @ 2020-08-30 79/week @ 2020-09-06 15/week @ 2020-09-13 52/week @ 2020-09-20

59 downloads per month
Used in 5 crates (via taml)

MIT/Apache

12KB
79 lines

lazy-transform-str

Lib.rs Crates.io Docs.rs

Rust 1.42.0 Build Status Crates.io - License

GitHub open issues open pull requests crev reviews

Lazy-copying lazy-allocated scanning str transformations.

This is good e.g. for (un)escaping text, especially if individual strings are short.

Installation

Please use cargo-edit to always add the latest version of this library:

cargo add lazy-transform-str

Example

use {
    cervine::Cow,
    gnaw::Unshift as _,
    lazy_transform_str::{Transform as _, TransformedPart},
    smartstring::alias::String,
};

fn double_a(str: &str) -> Cow<String, str> {
    str.transform(|rest /*: &mut &str */| {
        // Consume some of the input. `rest` is never empty here.
        match rest.unshift().unwrap() {
            'a' => TransformedPart::Changed(String::from("aa")),
            _ => TransformedPart::Unchanged,
        }
    } /*: impl FnMut(…) -> … */ )
}

assert_eq!(double_a("abc"), Cow::Owned(String::from("aabc")));
assert_eq!(double_a("bcd"), Cow::Borrowed("bcd"));

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Code of Conduct

Changelog

Versioning

lazy-transform-str strictly follows Semantic Versioning 2.0.0 with the following exceptions:

  • The minor version will not reset to 0 on major version changes (except for v1).
    Consider it the global feature level.
  • The patch version will not reset to 0 on major or minor version changes (except for v0.1 and v1).
    Consider it the global patch level.

This includes the Rust version requirement specified above.
Earlier Rust versions may be compatible, but this can change with minor or patch releases.

Which versions are affected by features and patches can be determined from the respective headings in CHANGELOG.md.

Dependencies

~155KB