chore: reorg
This commit is contained in:
72
__serialization/encoding/Cargo.lock
generated
Normal file
72
__serialization/encoding/Cargo.lock
generated
Normal file
@@ -0,0 +1,72 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "encoding"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"encoding 0.2.33",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding"
|
||||
version = "0.2.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
|
||||
dependencies = [
|
||||
"encoding-index-japanese",
|
||||
"encoding-index-korean",
|
||||
"encoding-index-simpchinese",
|
||||
"encoding-index-singlebyte",
|
||||
"encoding-index-tradchinese",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding-index-japanese"
|
||||
version = "1.20141219.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91"
|
||||
dependencies = [
|
||||
"encoding_index_tests",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding-index-korean"
|
||||
version = "1.20141219.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81"
|
||||
dependencies = [
|
||||
"encoding_index_tests",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding-index-simpchinese"
|
||||
version = "1.20141219.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7"
|
||||
dependencies = [
|
||||
"encoding_index_tests",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding-index-singlebyte"
|
||||
version = "1.20141219.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a"
|
||||
dependencies = [
|
||||
"encoding_index_tests",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding-index-tradchinese"
|
||||
version = "1.20141219.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
|
||||
dependencies = [
|
||||
"encoding_index_tests",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_index_tests"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
|
||||
11
__serialization/encoding/Cargo.toml
Normal file
11
__serialization/encoding/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "encoding"
|
||||
version = "0.1.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
encoding = "0.2.33"
|
||||
|
||||
30
__serialization/encoding/src/main.rs
Normal file
30
__serialization/encoding/src/main.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use encoding::{
|
||||
all::GBK,
|
||||
Encoding,
|
||||
EncoderTrap,
|
||||
DecoderTrap,
|
||||
};
|
||||
|
||||
fn gbk_to_utf8_bytes(b: &[u8]) -> Option<Vec<u8>> {
|
||||
match GBK.decode(b, DecoderTrap::Strict) {
|
||||
Err(_) => None,
|
||||
Ok(s) => Some(s.as_bytes().to_vec()),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let h_china = GBK.encode("Hello 中国", EncoderTrap::Strict)?;
|
||||
|
||||
let d_china = GBK.decode(&h_china, DecoderTrap::Strict)?;
|
||||
|
||||
println!("Encoding name: {}, whatwg name: {}", GBK.name(), GBK.whatwg_name().unwrap_or("None"));
|
||||
println!("{:?}", h_china);
|
||||
println!("{:?}", d_china);
|
||||
|
||||
let utf8_vec = gbk_to_utf8_bytes(&h_china[..]);
|
||||
if let Some(u8_vec) = utf8_vec {
|
||||
println!("{:?}", String::from_utf8(u8_vec)?);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user