#page #windows #dos #code

codepage-437

为Rust编写的Codepage 437转码

1个不稳定版本

使用旧的Rust 2015

0.1.0 2018年2月24日

编码类别中排名第1225

Download history 2499/week @ 2024-03-14 2369/week @ 2024-03-21 2750/week @ 2024-03-28 2378/week @ 2024-04-04 2179/week @ 2024-04-11 2400/week @ 2024-04-18 1796/week @ 2024-04-25 2639/week @ 2024-05-02 2509/week @ 2024-05-09 1642/week @ 2024-05-16 1359/week @ 2024-05-23 1683/week @ 2024-05-30 3313/week @ 2024-06-06 2257/week @ 2024-06-13 1825/week @ 2024-06-20 2207/week @ 2024-06-27

每月下载量达9,855次
14个crate(直接使用7个)中使用

MIT授权许可

33KB
386

codepage-437 TravisCI构建状态 AppVeyorCI构建状态 许可

为Rust编写的Code page 437转码。

文档


lib.rs:

将数据转换为和从codepage 437。

使用{Borrow,}FromCp437 traits将一系列cp437字节转换为Unicode,并使用cp437_to_unicode()函数解码单个码点。

使用{Into,To}Cp437 traits将Unicode转换为一系列cp437字节,并使用unicode_to_cp437()函数编码单个码点。

示例

从缓冲区借用

let data = &[/* buffer acquired somewhere */];

/// in_unicode will be Cow::Borrowed if data only contains overlapping characters,
///                 or Cow::Owned if a conversion needed to have been made.
let in_unicode = Cow::borrow_from_cp437(data, &CP437_CONTROL);

// Also valid:
let in_unicode = String::borrow_from_cp437(data, &CP437_CONTROL);

从缓冲区中移出

let data = vec![/* buffer moved in from somewhere */];

/// data is moved out of and zero-alloced into in_unicode
///      if it only contains overlapping characters
let in_unicode = String::from_cp437(data, &CP437_CONTROL);

&str借用

let data = "Some string.";

/// in_cp437 will be Cow::Borrowed if data only contains overlapping characters,
///                  Cow::Owned if a conversion needed to have been made,
///               or Err, if data can't be represented as cp437
let in_cp437 = data.to_cp437(&CP437_CONTROL);

// Also valid (String is AsRef<str>):
let data = "Some string.".to_string();
let in_cp437 = data.to_cp437(&CP437_CONTROL);

String中移出

let data = "Some string.".to_string();

/// data is moved out of and zero-alloced into in_cp437
///      if it only contains overlapping characters
let in_cp437 = data.into_cp437(&CP437_CONTROL);

无法表示的Unicode

// Ż has no representation in cp437
let data = "Jurek żelaznym żurkiem żre żupan.";

let result = data.to_cp437(&CP437_CONTROL);
assert!(result.is_err());
// result.unwrap_err() is Cp437Error (or IntoCp437Error for into_cp437()),
//   with an API modeled after libstd's {From,}Utf8Error

无运行时依赖

~170KB