6个版本

使用旧的Rust 2015

0.2.4 2017年9月15日
0.2.3 2017年9月5日
0.1.0 2017年8月24日

文本处理中排名第632

Download history 14021/week @ 2023-12-18 515/week @ 2023-12-25 4031/week @ 2024-01-01 4491/week @ 2024-01-08 4012/week @ 2024-01-15 8688/week @ 2024-01-22 4957/week @ 2024-01-29 6864/week @ 2024-02-05 8629/week @ 2024-02-12 2883/week @ 2024-02-19 10057/week @ 2024-02-26 3643/week @ 2024-03-04 8279/week @ 2024-03-11 7276/week @ 2024-03-18 12870/week @ 2024-03-25 12986/week @ 2024-04-01

每月下载量41,520
25crate使用(其中16个直接使用)

LGPL-3.0

2MB
12K SLoC

Rust-Chardet

Rust-Charset on Travis CI

Rust版本chardet。

使用方法

将以下内容放入你的Cargo.toml

[dependencies]
chardet = "0.2"

然后在crate根目录中放入以下内容

extern crate chardet;

与编码一起使用

extern crate chardet;
extern crate encoding;
use chardet;
use std::fs::OpenOptions;
use std::io::prelude::*;
use encoding::DecoderTrap;
use encoding::label::encoding_from_whatwg_label;

// open text file
let mut fh = OpenOptions::new().read(true).open(filepath).expect(
    "Could not open file",
);
let mut reader: Vec<u8> = Vec::new();

// read file
fh.read_to_end(&mut reader).expect("Could not read file");

// detect charset of the file
let result = detect(&reader);
// result.0 Encode
// result.1 Confidence
// result.2 Language

// decode file into utf-8
let coder = encoding_from_whatwg_label(charset2encoding(&result.0));
if coder.is_some() {
    let utf8reader = coder.unwrap().decode(&reader, DecoderTrap::Ignore).expect("Error");
}

无运行时依赖