#ord #ascii #character #unicode #unicode-characters #chr #rfc20

asciis

基于RFC20的ASCII。只有ord()和chr()这两个方法。

4个版本

0.1.3 2019年8月18日
0.1.2 2019年8月18日
0.1.1 2019年8月18日
0.1.0 2019年8月18日

#1923 in 文本处理

MIT/Apache

780KB
331

包含 (WOFF字体,190KB) target/doc/FiraSans-Medium.woff,(WOFF字体,185KB) target/doc/FiraSans-Regular.woff,(WOFF字体,94KB) target/doc/SourceSerifPro-Bold.ttf.woff,(WOFF字体,89KB) SourceSerifPro-Regular.ttf.woff,(WOFF字体,56KB) target/doc/SourceCodePro-Regular.woff,(WOFF字体,56KB) target/doc/SourceCodePro-Semibold.woff 和更多

asciis

Rust-lang: 基于ASCII规范文档RFC20编写的库。这个库非常简单易用,因为只有ord()和chr()这两个方法

基于ASCII规范文档RFC20编写的库。这个库非常简单易用,因为只有ord()和chr()这两个方法

使用方法

ord

给定一个表示一个Unicode字符的字符串,返回表示该字符Unicode码点的整数。

例如,ord('a')返回整数Some(97)和ord("s")返回Some(115)。

这是chr()的逆操作。

chr

返回表示整数i的Unicode码点的字符的字符串。

例如,chr(97)返回Some(),而chr(115)返回String Some("s")。

这是ord()的逆操作。

ord()

&str to Some(i32), "s" -> Some(115)

示例

use asciis::asc::Asciis;
let asc = Asciis{};
let r = asc.ord("s");
assert_eq!(r, Some(115));

chr()

i32 to Some(String), 97 -> Some("a") 示例

use asciis::asc::Asciis;
let asc = Asciis{};
let v = asc.chr(97);
assert_eq!(v, Some(String::from("a")));

常见问题解答

问:为什么返回值的类型是Option,而不是i32或String?

为什么返回值的类型是Option,而不是i32或String?

A: The ascii value range is [0~127], which can cause panic! if exceeded. So Option better than i32 or String.

ASCII 码的范围是 [0~127],超出范围就会引发 panic!。所以 Optioni32 或者 String 更合适。

问:Rust标准库std中已经有了AsciiExt,为什么还要写这个库?

Rust标准库std中已经有了AsciiExt,为什么还要写这个库?

A: Python's simple style influenced me. ord() and chr() are very simple to use.

Python 简约的风格影响着我,我觉得 ord()chr() 这种方式更好用。

问:这些标准代码从哪里来?

这些标准代码从哪里来?

A: From the RFC20 https://tools.ietf.org/html/rfc20#section-2

详见 RFC20 文档的第 2 部分介绍 https://tools.ietf.org/html/rfc20#section-2

问:我如何确定ord()方法应该传入什么值?

我如何确定ord()方法应该传入什么值?

A:See https://tools.ietf.org/html/rfc20#section-2

跟上面一样,详见 RFC20 文档的第 2 部分介绍,这是 ASCII 规范中约定的值

无运行时依赖