1 个稳定版本
1.0.0 | 2023 年 9 月 6 日 |
---|
14 in #conversions
11KB
144 行代码(不含注释)
IBM-1047
Rust 中 IBM-1047 的转换
\n
被编码为 0x15
和 U+0085
被编码为 0x25
。
使用方法
use ibm1047::Encode;
// Warning: flatten will discard characters that cannot be encoded as IBM-1047.
let ebcdic: Vec<u8> = "Hello, World!\n".encode_ibm1047().flatten().collect();
let string: String = ibm1047::decode(&ebcdic).collect();
assert_eq!(string, "Hello, World!\n");
直接解码为字符串需要 alloc
功能。
use ibm1047::Decode;
let name = String::from_ibm1047(&ebcdic);
lib.rs
:
将字符串转换为 IBM-1047 以及从 IBM-1047 转换为字符串。
use ibm1047::Encode;
// Warning: flatten will discard characters that cannot be encoded as IBM-1047.
let ebcdic: Vec<u8> = "Hello, World!\n".encode_ibm1047().flatten().collect();
let string: String = ibm1047::decode(&ebcdic).collect();
assert_eq!(string, "Hello, World!\n");