13个版本 (稳定版)

2.0.3 2023年11月13日
2.0.2 2023年2月11日
1.1.4 2019年2月4日
1.1.3 2018年10月21日
0.1.2 2018年10月12日

#2 in #字节序

Download history 115394/week @ 2024-04-23 106988/week @ 2024-04-30 107055/week @ 2024-05-07 113390/week @ 2024-05-14 108817/week @ 2024-05-21 110457/week @ 2024-05-28 109823/week @ 2024-06-04 108176/week @ 2024-06-11 107573/week @ 2024-06-18 102066/week @ 2024-06-25 99895/week @ 2024-07-02 102657/week @ 2024-07-09 106765/week @ 2024-07-16 111162/week @ 2024-07-23 108447/week @ 2024-07-30 104553/week @ 2024-08-06

每月下载 449,687
245 个crate中使用(直接使用9个)

Apache-2.0

23KB
369

unicode-bom

Build status Crate status Downloads License

Rust项目的Unicode字节序标记检测。

它做什么?

unicode-bom将从数组或磁盘上的文件中读取前几个字节,然后确定是否存在字节序标记。

它不做什么?

它不会检查其余数据以确定其是否根据指示的编码有效。

我该如何安装它?

将其添加到Cargo.toml中的依赖项。

[dependencies]
unicode-bom = "2"

我该如何使用它?

有关更多信息,请参阅API文档,但大致内容如下

use unicode_bom::Bom;

// The BOM can be parsed from a file on disk via the `FromStr` trait...
let bom: Bom = "foo.txt".parse().unwrap();
match bom {
    Bom::Null => {
        // No BOM was detected
    }
    Bom::Bocu1 => {
        // BOCU-1 BOM was detected
    }
    Bom::Gb18030 => {
        // GB 18030 BOM was detected
    }
    Bom::Scsu => {
        // SCSU BOM was detected
    }
    Bom::UtfEbcdic => {
        // UTF-EBCDIC BOM was detected
    }
    Bom::Utf1 => {
        // UTF-1 BOM was detected
    }
    Bom::Utf7 => {
        // UTF-7 BOM was detected
    }
    Bom::Utf8 => {
        // UTF-8 BOM was detected
    }
    Bom::Utf16Be => {
        // UTF-16 (big-endian) BOM was detected
    }
    Bom::Utf16Le => {
        // UTF-16 (little-endian) BOM was detected
    }
    Bom::Utf32Be => {
        // UTF-32 (big-endian) BOM was detected
    }
    Bom::Utf32Le => {
        // UTF-32 (little-endian) BOM was detected
    }
}

// ...or you can detect the BOM in a byte array
let bytes = [0u8, 0u8, 0xfeu8, 0xffu8];
let bom = Bom::from(&bytes[0..]);
assert_eq!(bom, Bom::Utf32Be);
assert_eq(bom.len(), 4);

我该如何设置构建环境?

如果您还没有安装Rust,请首先使用rustup安装。

curl https://sh.rustup.rs -sSf | sh

然后您可以构建项目

cargo b

并运行测试

cargo t

有API文档吗?

.

有变更日志吗?

.

它是根据什么许可证发布的?

Apache-2.0.

没有运行时依赖项