quoted-string Crates.io quoted-string License Build Status

This crate provides utilities to handle quoted strings like such appearing in Mediat Types (both MIME (i.e. Mail) and HTTP). As there are many small but significant differences in different specifications this crate does not provide a specific implementation. Instead a QuotedStringSpec trait is exposed. Implementing it (on zero-sized structs) should allow the usage with any quoted-string specification.

Available functionality contains

Example

```rust extern crate quoted_string;

// we use a QuotedStringSpec provided for testing here, // not that it's made to hitt some edcases in a simple way // so it does not correspond to any used real Spec use quotedstring::testutils::TestSpec; type Spec = TestSpec;

use quotedstring::{parse, quote, quoteifneeded, tocontent};

fn main() { let res = parse::("\"quoted\\"st\ring\"; tail=x").unwrap(); let qs = res.quotedstring; asserteq!(qs, "\"quoted\\"st\ring\""); asserteq!(res.tail, "; tail=x"); let content = tocontent::(qs) .expect("[BUG] tocontent is guaranteed to succeed if input is a valid quoted string"); asserteq!(content, "quoted\"string"); let (requoted, meta) = quote::(&*content) .expect("[BUG] quote is guaranteed to succeed if the input is representable in a quoted string"); asserteq!(requoted, "\"quoted\\"string\"");

// TestSpec specifies us-ascii words with 6 letters need no quoting
let (out, _meta) = quote_if_needed::<Spec>("simple").unwrap();
assert_eq!(&*out, "simple");

}

```

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.

Change Log