2 个版本

0.1.1 2023 年 12 月 1 日
0.1.0 2023 年 12 月 1 日
0.0.1 2023 年 11 月 30 日

#812文本处理

Download history · Rust 包仓库 3211/week @ 2024-04-08 · Rust 包仓库 3734/week @ 2024-04-15 · Rust 包仓库 3317/week @ 2024-04-22 · Rust 包仓库 2975/week @ 2024-04-29 · Rust 包仓库 3405/week @ 2024-05-06 · Rust 包仓库 3268/week @ 2024-05-13 · Rust 包仓库 1609/week @ 2024-05-20 · Rust 包仓库 2307/week @ 2024-05-27 · Rust 包仓库 2622/week @ 2024-06-03 · Rust 包仓库 3010/week @ 2024-06-10 · Rust 包仓库 3258/week @ 2024-06-17 · Rust 包仓库 2760/week @ 2024-06-24 · Rust 包仓库 1494/week @ 2024-07-01 · Rust 包仓库 2529/week @ 2024-07-08 · Rust 包仓库 4008/week @ 2024-07-15 · Rust 包仓库 2440/week @ 2024-07-22 · Rust 包仓库

10,567 每月下载量
用于 73 个 crates (2 直接)

Apache-2.0

50KB
987 代码行

escape-bytes

转义非可打印 ASCII 字符的字节。

确切规则是

  • 空字符被转义为 \0
  • 制表符被转义为 \t
  • 换行符被转义为 \n
  • 回车符被转义为 \r
  • 反斜杠被转义为 \\
  • 可打印 ASCII 范围内的任何字符(0x20..=0x7e)不会被转义。
  • 其他任何字符将以十六进制形式转义,格式为 \xNN

适用于字节序列不合法 ASCII 或 UTF-8 但需要以半人类可读形式存储,而只允许 ASCII 或 UTF-8 的情况。

示例

转义

let str = b"hello\xc3world";
let escaped = escape_bytes::escape(str);
assert_eq!(escaped, br"hello\xc3world");

反转义

let escaped = br"hello\xc3world";
let unescaped = escape_bytes::unescape(escaped)?;
assert_eq!(unescaped, b"hello\xc3world");

许可证:Apache-2.0


lib.rs:

转义非可打印 ASCII 字符的字节。

确切规则是

  • 空字符被转义为 \0
  • 制表符被转义为 \t
  • 换行符被转义为 \n
  • 回车符被转义为 \r
  • 反斜杠被转义为 \\
  • 可打印 ASCII 范围内的任何字符(0x20..=0x7e)不会被转义。
  • 其他任何字符将以十六进制形式转义,格式为 \xNN

适用于字节序列不合法 ASCII 或 UTF-8 但需要以半人类可读形式存储,而只允许 ASCII 或 UTF-8 的情况。

示例

转义

let str = b"hello\xc3world";
let escaped = escape_bytes::escape(str);
assert_eq!(escaped, br"hello\xc3world");

反转义

let escaped = br"hello\xc3world";
let unescaped = escape_bytes::unescape(escaped)?;
assert_eq!(unescaped, b"hello\xc3world");

无运行时依赖

功能