residua-mutf8

A simple library for converting between MUTF-8 and UTF-8.

![Build Status] ![Latest Version]

Documentation

View the full reference on docs.rs here.

Usage

This crate is on crates.io and can be used by adding residua-mutf8 to your dependencies in your project's Cargo.toml:

toml [dependencies] residua-mutf8 = "1"

Examples

Basic usage

```rust use std::borrow::Cow; use mutf8::{tomutf8, frommutf8};

let str = "Hello, world!"; // 16-bit Unicode characters are the same in UTF-8 and MUTF-8: asserteq!(tomutf8(str), Cow::Borrowed(str.asbytes())); asserteq!(frommutf8(str.asbytes()), Ok(Cow::Borrowed(str)));

let str = "\u{10401}"; let mutf8data = &[0xED, 0xA0, 0x81, 0xED, 0xB0, 0x81]; // 'mutf8data' is a byte slice containing a 6-byte surrogate pair which // becomes a 4-byte UTF-8 character. asserteq!(frommutf8(mutf8data), Ok(Cow::Owned(str.tostring())));

let str = "\0"; let mutf8data = &[0xC0, 0x80]; // 'str' is a null character which becomes a two-byte MUTF-8 representation. asserteq!(tomutf8(str), Cow::<[u8]>::Owned(mutf8data.to_vec())); ```

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.