This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
api:unicode:zh [2023/10/14 17:15] hfsr [Unicode API] translate to zh_cn |
api:unicode:zh [2023/11/30 09:14] (current) hfsr [Unicode API] |
||
---|---|---|---|
Line 1: | Line 1: | ||
Unicode API | Unicode API | ||
========== | ========== | ||
- | 所有的字符串数据都需要在某些时候通过Java传递,因此在处理它们时添加Unicode支持可能会有所帮助(因为Java内部的字符串使用UTF-8编码)。尤其是屏幕会显示UTF-8字符串,意味着相关的GPU函数需要接收UTF-8字符串。而且键盘输入通常也会以UTF-8编码,尤其是剪切板。 | + | 所有的字符串数据都需要在某些时候通过Java传递,因此在处理它们时添加Unicode支持可能会有所帮助(因为Java内部的字符串使用UTF-8编码)。具体而言,屏幕会显示UTF-8字符串,意味着相关的GPU函数需接收UTF-8字符串。而且键盘输入通常也会以UTF-8编码,尤其是剪切板。 |
- | 但是请记住,尽管电脑可以显示宽字符(例如汉字),但是OpenOS的软件(命令行、文本编辑器和Lua解释器)对其输入输出的支持并不全面。 | + | 但是请记住,尽管电脑可以显示宽字符,但OpenOS的软件(shell、edit和Lua解释器)对其输入输出的支持并不全面。 |
我们提供下列函数以支持基本的UTF-8处理: | 我们提供下列函数以支持基本的UTF-8处理: | ||
- `unicode.char(value: number, ...): string` | - `unicode.char(value: number, ...): string` | ||
- | `string.char`的可支持UTF-8版本。传入值限定为整个UTF-8取值范围,不仅仅是ASCII。 | + | `string.char`的可支持UTF-8版本。传入值限定为整个UTF-8取值范围,不仅仅是ASCII。 |
+ | \\ | ||
- `unicode.charWidth(value: string, ...): number` | - `unicode.charWidth(value: string, ...): number` | ||
- | 返回给定字符串中第一个字符的宽度。例如,给定`シ`将会返回`2`,给定`a`将会返回`1`。 | + | 返回给定字符串中第一个字符的宽度。例如,给定`シ`将会返回`2`,给定`a`将会返回`1`。 |
+ | \\ | ||
- `unicode.isWide(value: string, ...): boolean` | - `unicode.isWide(value: string, ...): boolean` | ||
- | 返回给定字符串中第一个字符的宽度是否大于1。例如,给定`シ`将会返回`true`,给定`a`将会返回`false'`。 | + | 返回给定字符串中第一个字符的宽度是否大于1。例如,给定`シ`将会返回`true`,给定`a`将会返回`false'`。 |
+ | \\ | ||
- `unicode.len(value: string): number` | - `unicode.len(value: string): number` | ||
- | `string.len`的可支持UTF-8版本。例如,给定`Ümläüt`将会返回`6`而`string.len`会返回`9`。 | + | `string.len`的可支持UTF-8版本。例如,给定`Ümläüt`,本函数将会返回`6`,而`string.len`会返回`9`。 |
+ | \\ | ||
- `unicode.lower(value: string): string` | - `unicode.lower(value: string): string` | ||
- | `string.lower`的可支持UTF-8版本。 | + | `string.lower`的可支持UTF-8版本。 |
+ | \\ | ||
- `unicode.reverse(value: string): string` | - `unicode.reverse(value: string): string` | ||
- | `string.reverse`的可支持UTF-8版本。例如,给定`Ümläüt`将会返回`tüälmÜ`而`string.reverse` 会返回`tälm`。 | + | `string.reverse`的可支持UTF-8版本。例如,给定`Ümläüt`,本函数将会返回`tüälmÜ`,而`string.reverse` 会返回`tälm`。 |
+ | \\ | ||
- `unicode.sub(value: string, i:number[, j:number]): string` | - `unicode.sub(value: string, i:number[, j:number]): string` | ||
- | `string.sub`的可支持UTF-8版本。 | + | `string.sub`的可支持UTF-8版本。 |
+ | \\ | ||
- `unicode.upper(value: string): string` | - `unicode.upper(value: string): string` | ||
- | `string.upper`的可支持UTF-8版本。 | + | `string.upper`的可支持UTF-8版本。 |
+ | \\ | ||
- `unicode.wlen(value: string): number` | - `unicode.wlen(value: string): number` | ||
- | 返回整个字符串的宽度。 | + | 返回整个字符串的宽度。 |
+ | \\ | ||
- `unicode.wtrunc(value: string, count: number): string` | - `unicode.wtrunc(value: string, count: number): string` | ||
截取给定字符串的前`count`位,不含此位。如果字符串长度不足给定的`count`数,函数将会报错。 | 截取给定字符串的前`count`位,不含此位。如果字符串长度不足给定的`count`数,函数将会报错。 |