8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

12.13.1 字符定义数组12.13.1 Character Definition Arrays

每个简单字符集都有一个配置文件,位于 sql/share/charsets 目录中。对于名为 MYSYS 的字符集,该文件名为 MYSET.xml。它使用 <map> 数组元素列出字符集属性。<map> 元素出现在以下元素中:Each simple character set has a configuration file located in the sql/share/charsets directory. For a character set named MYSYS, the file is named MYSET.xml. It uses <map> array elements to list character set properties. <map> elements appear within these elements:

  • <ctype> 定义每个字符的属性。<ctype> defines attributes for each character.

  • <lower> 和 <upper> 列出小写和大写字符。<lower> and <upper> list the lowercase and uppercase characters.

  • <unicode> 将 8 位字符值映射到 Unicode 值。<unicode> maps 8-bit character values to Unicode values.

  • <collation> 元素表示用于比较和排序的字符顺序,每个排序规则一个元素。二进制排序规则不需要 <map> 元素,因为字符码本身就提供了顺序。<collation> elements indicate character ordering for comparison and sorting, one element per collation. Binary collations need no <map> element because the character codes themselves provide the ordering.

对于在 strings 目录下的 ctype-MYSET.c 文件中实现的复杂字符集,有相应的数组:ctype_MYSET[]、to_lower_MYSET[] 等等。并非每个复杂字符集都包含所有数组。另请参见现有的 ctype-*.c 文件以获取示例。更多信息请查看 strings 目录下的 CHARSET_INFO.txt 文件。For a complex character set as implemented in a ctype-MYSET.c file in the strings directory, there are corresponding arrays: ctype_MYSET[], to_lower_MYSET[], and so forth. Not every complex character set has all of the arrays. See also the existing ctype-*.c files for examples. See the CHARSET_INFO.txt file in the strings directory for additional information.

大多数数组以字符值为索引,并有 256 个元素。<ctype> 数组以字符值 1 为索引,并有 257 个元素。这是用于处理 EOF 的传统约定。Most of the arrays are indexed by character value and have 256 elements. The <ctype> array is indexed by character value + 1 and has 257 elements. This is a legacy convention for handling EOF.

<ctype> 数组元素是位值。每个元素描述字符集中单个字符的属性。每个属性都与一个位掩码相关,如 include/m_ctype.h 中定义的那样:<ctype> array elements are bit values. Each element describes the attributes of a single character in the character set. Each attribute is associated with a bitmask, as defined in include/m_ctype.h:

#define _MY_U   01      /* Upper case */
#define _MY_L   02      /* Lower case */
#define _MY_NMR 04      /* Numeral (digit) */
#define _MY_SPC 010     /* Spacing character */
#define _MY_PNT 020     /* Punctuation */
#define _MY_CTR 040     /* Control character */
#define _MY_B   0100    /* Blank */
#define _MY_X   0200    /* heXadecimal digit */

给定字符的 <ctype> 值应为描述该字符的适用位掩码值的并集。例如,'A' 是一个大写字符(_MY_U)也是一个十六进制数字(_MY_X),所以它的 ctype 值应这样定义:The <ctype> value for a given character should be the union of the applicable bitmask values that describe the character. For example, 'A' is an uppercase character (_MY_U) as well as a hexadecimal digit (_MY_X), so its ctype value should be defined like this:

ctype['A'+1] = _MY_U | _MY_X = 01 | 0200 = 0201

m_ctype.h 中的位掩码值是八进制值,但 <ctype> 数组在 MYSET.xml 中的元素应以十六进制值书写。The bitmask values in m_ctype.h are octal values, but the elements of the <ctype> array in MYSET.xml should be written as hexadecimal values.

<lower> 和 <upper> 数组保存与字符集每个成员对应的小写和大写字符。例如:The <lower> and <upper> arrays hold the lowercase and uppercase characters corresponding to each member of the character set. For example:

lower['A'] should contain 'a'
upper['a'] should contain 'A'

每个 <collation> 数组表示字符在比较和排序时的顺序。MySQL 根据这些信息的值对字符进行排序。在某些情况下,这与 <upper> 数组相同,这意味着排序不区分大小写。对于更复杂的排序规则(针对复杂字符集),请参阅 第 12.13.2 节,“复杂字符集的字符串排序支持” 中关于字符串排序的讨论。Each <collation> array indicates how characters should be ordered for comparison and sorting purposes. MySQL sorts characters based on the values of this information. In some cases, this is the same as the <upper> array, which means that sorting is case-insensitive. For more complicated sorting rules (for complex character sets), see the discussion of string collating in Section 12.13.2, “String Collating Support for Complex Character Sets”.