This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
api:unicode:zh [2022/08/11 10:51] fight_xing created |
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编码,尤其是剪切板。 | ||
- | **本篇文章的部分/全部内容还没有进行翻译。** | + | 但是请记住,尽管电脑可以显示宽字符,但OpenOS的软件(shell、edit和Lua解释器)对其输入输出的支持并不全面。 |
- | Because all strings pass through Java at some point it can be useful to handle them with Unicode support (since Java's internal string representation is UTF-8 encoded). In particular, screens display UTF-8 strings, meaning the related GPU functions expect UTF-8 strings. Also, keyboard input will generally be UTF-8 encoded, especially the clipboard. | + | 我们提供下列函数以支持基本的UTF-8处理: |
- | + | ||
- | However, keep in mind that while wide characters can be displayed, input and output of those is not fully supported in OpenOS's software (i.e. the shell, edit and Lua interpreter). | + | |
- | + | ||
- | The following functions are provided to allow basic UTF-8 handling: | + | |
- `unicode.char(value: number, ...): string` | - `unicode.char(value: number, ...): string` | ||
- | UTF-8 aware version of `string.char`. The values may be in the full UTF-8 range, not just ASCII. | + | `string.char`的可支持UTF-8版本。传入值限定为整个UTF-8取值范围,不仅仅是ASCII。 |
+ | \\ | ||
- `unicode.charWidth(value: string, ...): number` | - `unicode.charWidth(value: string, ...): number` | ||
- | Returns the width of the first character given. For example, for `シ` it'll return `2`, where `a` would return `1`. | + | 返回给定字符串中第一个字符的宽度。例如,给定`シ`将会返回`2`,给定`a`将会返回`1`。 |
+ | \\ | ||
- `unicode.isWide(value: string, ...): boolean` | - `unicode.isWide(value: string, ...): boolean` | ||
- | Returns if the width of the first character given is greater than 1. For example, for `シ` it'll return `true`, where `a` would return `false`. | + | 返回给定字符串中第一个字符的宽度是否大于1。例如,给定`シ`将会返回`true`,给定`a`将会返回`false'`。 |
+ | \\ | ||
- `unicode.len(value: string): number` | - `unicode.len(value: string): number` | ||
- | UTF-8 aware version of `string.len`. For example, for `Ümläüt` it'll return `6`, where `string.len` would return `9`. | + | `string.len`的可支持UTF-8版本。例如,给定`Ümläüt`,本函数将会返回`6`,而`string.len`会返回`9`。 |
+ | \\ | ||
- `unicode.lower(value: string): string` | - `unicode.lower(value: string): string` | ||
- | UTF-8 aware version of `string.lower`. | + | `string.lower`的可支持UTF-8版本。 |
+ | \\ | ||
- `unicode.reverse(value: string): string` | - `unicode.reverse(value: string): string` | ||
- | UTF-8 aware version of `string.reverse`. For example, for `Ümläüt` it'll return `tüälmÜ`, where `string.reverse` would return `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` | ||
- | UTF-8 aware version of `string.sub`. | + | `string.sub`的可支持UTF-8版本。 |
+ | \\ | ||
- `unicode.upper(value: string): string` | - `unicode.upper(value: string): string` | ||
- | UTF-8 aware version of `string.upper`. | + | `string.upper`的可支持UTF-8版本。 |
+ | \\ | ||
- `unicode.wlen(value: string): number` | - `unicode.wlen(value: string): number` | ||
- | Returns the width of the entire string. | + | 返回整个字符串的宽度。 |
+ | \\ | ||
- `unicode.wtrunc(value: string, count: number): string` | - `unicode.wtrunc(value: string, count: number): string` | ||
- | Truncates the given string up to but not including `count` width. If there are not enough characters to match the wanted width, the function errors. | + | 截取给定字符串的前`count`位,不含此位。如果字符串长度不足给定的`count`数,函数将会报错。 |
- | For example, these are used when files are opened in non-binary mode. The original string functions are used for files opened in binary mode. | + | 上述函数被用于以非二进制模式打开文件时,而原版字符串处理函数被用于以二进制模式打开文件时。 |
目录 | 目录 | ||
----------- | ----------- | ||
{{page>api:contents:zh&noheader&noeditbutton&nouser&nofooter}} | {{page>api:contents:zh&noheader&noeditbutton&nouser&nofooter}} |