我试图真正理解 unicode 标准并且正在浏览 xml spec它写着:
Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
现在我有几个问题:
谢谢澄清!
最佳答案
What are the surrogate blocks?
U+D800
中的 Unicode 代码点至 U+DFFF
范围,包括,保留作为 UTF-16 代理专用,在任何其他上下文中都是非法的。Are they the UTF-16 codes that indicate a 4 byte code point?
是的。
Does #xXXXX refer to the code point or to the UTF-16 encoded value here?
实际的 Unicode 代码点。考虑到
Char
的定义包括值 > #xFFFF,单个编码的 UTF-16 值不能超过。 UTF 是代码点值的字节编码方案。 XML 规范是根据代码点而不是编码编写的。出于存储和传输的目的,可以使用 XML prolog 的“encoding”属性中指定的任何字符集对 XML 文档进行编码,但实际的 XML 内容是根据未编码的代码点处理的。If it refers to the code point and my understanding of the surrogate blocks is correct: Why are the surrogate blocks mentioned here?
代理代码点是保留的,不允许在任何文本内容中出现未编码。
Char
定义只是强制执行该规则。Why are non-characters like "U+FFFE" defined as part of the unicode standard? As to my understanding, Byte-order detection (as well as handling flexible sized code words) is up to the encoding.
因为编码并不总是提前知道,可能需要动态检测。
U+FFFE
用作 BOM 标记以帮助促进这一点。允许使用早期版本的 Unicode U+FFFE
用作 BOM 或文本内容中的实际不间断空格字符。这有时会导致模棱两可。所以较新版本的 Unicode 保留 U+FFFE
严格仅作为 BOM 表,不间断间距由 U+2060 WORD JOINER
处理而是为了避免任何歧义。话虽如此,在 XML 的上下文中,使用
U+FFFE
没有意义。在任何文本内容中。整个文档以特定的字符集编码,使用的任何 BOM 都必须出现在 XML 序言之前。 XML 规范定义了 XML 文档本身之外的 BOM 处理和字符集检测。所以这就是为什么 Char
定义不包括 U+FFFE
.U+FFFF
是保留的,并不打算在实践中用于实际内容。所以这就是为什么 Char
定义排除了它。所以基本上是
Char
定义允许所有 Unicode 代码点减去受限代码点。
关于unicode - 了解 Unicode : Surrogate Blocks, 非字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36954070/