textcode 0.3.1

Text encoding/decoding library. Supports: UTF-8, ISO6937, ISO8859, GB2312
Documentation
use textcode::{
    Utf8,
    decode,
    encode,
};

#[test]
fn test_utf8() {
    let u = "ะขะตัั‚ ๐Ÿ˜€";
    let c: &[u8] = &[
        0xd0, 0xa2, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0x20, 0xf0, 0x9f, 0x98, 0x80,
    ];

    let enc = encode::<Utf8>(u);
    assert_eq!(c, enc.as_slice());

    let dec = decode::<Utf8>(c);
    assert_eq!(u, dec.as_str());
}

#[test]
fn test_utf8_n_bytes() {
    let u = "n ั‚ะตัั‚๐Ÿ˜นx";
    let c: &[u8] = &[
        // 1: 'n'
        0x6e, // 2: ' '
        0x20, // 3..4: 'ั‚'
        0xd1, 0x82, // 5..6: 'ะต'
        0xd0, 0xb5, // 7..8: 'ั'
        0xd1, 0x81, // 9..10: 'ั‚'
        0xd1, 0x82, // 11..14: '๐Ÿ˜น'
        0xf0, 0x9f, 0x98, 0xb9, // 15: x
        0x78,
    ];

    let enc = encode::<Utf8>(u);
    assert_eq!(c, enc.as_slice());

    let dec = decode::<Utf8>(c);
    assert_eq!(u, dec.as_str());
}