Unicode is a computing industry standard allowing computers to consistently represent and manipulate text expressed in most of the world‘s writing systems. Developed in tandem with the Universal Character Set standard and published in book form as The Unicode Standard, the latest version of Unicode consists of
l a repertoire of more than 107,000 characters covering 90 scripts,
l a set of code charts for visual reference,
l an encoding methodology and set of standard character encodings,
l an enumeration of character properties such as upper and lower case,
l a set of reference data computer files,
l a number of related items, such as character properties, rules for normalization, decomposition, collation, rendering, and bidirectional display order (for the correct display of text containing both right-to-left scripts, such as Arabic or Hebrew, and left-to-right scripts).
In computer science, the terms character encoding, character set, and sometimes character map or code page were historically synonymous, as the same standard would specify a repertoire of characters and how they were to be encoded into a stream of code units — usually with a single character per code unit. The terms now have related but distinct meanings, reflecting the efforts of standards bodies to use precise terminology when writing about and unifying many different encoding systems.[1] Regardless, the terms are still used interchangeably, with character set being nearly ubiquitous.
Unicode and its parallel standard, the ISO/IEC 10646 Universal Character Set together constitute a modern, unified character encoding. Rather than mapping characters directly to octets (bytes), they separately define what characters are available, their numbering, how those numbers are encoded as a series of "code units" (limited-size numbers), and finally how those units are encoded as a stream of octets. The idea behind this decomposition is to establish a universal set of characters that can be encoded in a variety of ways.[1] To correctly describe this model one needs more precise terms than "character set" and "character encoding". The terms used in the modern model follow:[1]
A character repertoire is the full set of abstract characters that a system supports. The repertoire may be closed, i.e. no additions are allowed without creating a new standard (as is the case with ASCII and most of the ISO-8859 series), or it may be open, allowing additions (as is the case with Unicode and to a limited extent the Windows code pages). The characters in a given repertoire reflect decisions that have been made about how to divide writing systems into linear information units. The basic variants of the Latin, Greek, and Cyrillic alphabets, can be broken down into letters, digits, punctuation, and a few special characters like the space, which can all be arranged in simple linear sequences that are displayed in the same order they are read. Even with these alphabets however diacritics pose a complication: they can be regarded either as part of a single character containing a letter and diacritic (known in modern terminology as a precomposed character), or as separate characters. The former allows a far simpler text handling system but the latter allows any letter/diacritic combination to be used in text. Other writing systems, such as Arabic and Hebrew, are represented with more complex character repertoires due to the need to accommodate things like bidirectional text and glyphs that are joined together in different ways for different situations.
A coded character set specifies how to represent a repertoire of characters using a number of non-negative integer codes called code points. For example, in a given repertoire, a character representing the capital letter "A" in the Latin alphabet might be assigned to the integer 65, the character for "B" to 66, and so on. A complete set of characters and corresponding integers is a coded character set. Multiple coded character sets may share the same repertoire; for example ISO/IEC 8859-1 and IBM code pages 037 and 500 all cover the same repertoire but map them to different codes. In a coded character set, each code point only represents one character, i.e., a coded character set is a function.
A character encoding form (CEF) specifies the conversion of a coded character set‘s integer codes into a set of limited-size integer code valuesthat facilitate storage in a system that represents numbers in binary form using a fixed number of bits (i.e. practically any computer system). For example, a system that stores numeric information in 16-bit units would only be able to directly represent integers from 0 to 65,535 in each unit, but larger integers could be represented if more than one 16-bit unit could be used. This is what a CEF accommodates: it defines a way of mapping a single code point from a range of, say, 0 to 1.4 million, to a series of one or more code values from a range of, say, 0 to 65,535.
The simplest CEF system is simply to choose large enough units that the values from the coded character set can be encoded directly (one code point to one code value). This works well for coded character sets that fit in 8 bits (as most legacy non-CJK encodings do) and reasonably well for coded character sets that fit in 16 bits (such as early versions of Unicode). However, as the size of the coded character set increases (e.g. modern Unicode requires at least 21 bits/character), this becomes less and less efficient, and it is difficult to adapt existing systems to use larger code values. Therefore, most systems working with later versions of Unicode use either UTF-8, which maps Unicode code points to variable-length sequences of octets, or UTF-16/UCS-2, which maps Unicode code points to variable-length sequences of 16-bit words.
Next, a character encoding scheme (CES) specifies how the fixed-size integer code values should be mapped into an octet sequence suitable for saving on an octet-based file system or transmitting over an octet-based network. With Unicode, a simple character encoding scheme is used in most cases, simply specifying whether the bytes for each integer should be in big-endian or little-endian order (even this isn‘t needed with UTF-8). However, there are also compound character encoding schemes, which use escape sequences to switch between several simple schemes (such as ISO/IEC 2022), and compressing schemes, which try to minimise the number of bytes used per code unit (such as SCSU, BOCU, and Punycode).
Finally, there may be a higher level protocol which supplies additional information that can be used to select the particular variant of a Unicode character, particularly where there are regional variants that have been ‘unified‘ in Unicode as the same character. An example is the XML attribute xml:lang.
The Unicode model reserves the term character map for historical systems which directly assign a sequence of characters to a sequence of bytes.[1] Such systems include entities which IBM‘s Character Data Representation Architecture (CDRA) designates with coded character set identifiers (CCIDs) and each of which is variously called a charset, character set, code page, or CHARMAP.[1] The term charset is also used for similar mappings by MIME and systems based on it.[1]
? Chinese Guobiao
? Taiwan Big5 (a more famous variant is Microsoft Code page 950)
? Hong Kong HKSCS
? Korean
The Universal Character Set (UCS), defined by the International Standard ISO/IEC 10646, Information technology — Universal multiple-octet coded character set (UCS) (plus amendments to that standard), is a standard set of characters upon which many character encodings are based.
Mapping of Unicode character planes
The Unicode characters can be categorized in many different ways, Unicode code points can be logically divided into 17 planes, each with 65,536 (= 216) code points, although currently only a few planes are used:
Currently, about ten percent of the potential space is used. Furthermore, ranges of characters have been tentatively blocked out for every current and ancient writing system (script) the Unicode consortium has been able to identify: (see [1]). While Unicode may eventually need to use another of the spare 11 planes for ideographic characters, other planes remain, if previously unknown scripts with tens of thousands of characters are discovered. This 21-bit limit is therefore unlikely to be reached in the near future.
The first plane (plane 0), the Basic Multilingual Plane (BMP),[Chandler1] is where most characters have been assigned so far. The BMP contains characters for almost all modern languages, and a large number of special characters. Most of the allocated code points in the BMP are used to encode Chinese, Japanese, and Korean (CJK) characters.
|
|
Note: Unicode characters visualization will depend on the character support of your web browser and the fonts installed on your system.
U+ |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
A |
B |
C |
D |
E |
F |
6000 |
怀 |
态 |
怂 |
怃 |
怄 |
怅 |
怆 |
怇 |
怈 |
怉 |
怊 |
怋 |
怌 |
怍 |
怎 |
怏 |
6010 |
怐 |
怑 |
怒 |
怓 |
怔 |
怕 |
怖 |
怗 |
怘 |
怙 |
怚 |
怛 |
怜 |
思 |
怞 |
怟 |
6020 |
怠 |
怡 |
怢 |
怣 |
怤 |
急 |
怦 |
性 |
怨 |
怩 |
怪 |
怫 |
怬 |
怭 |
怮 |
怯 |
6030 |
怰 |
怱 |
怲 |
怳 |
怴 |
怵 |
怶 |
怷 |
怸 |
怹 |
怺 |
总 |
怼 |
怽 |
怾 |
怿 |
6040 |
恀 |
恁 |
恂 |
恃 |
恄 |
恅 |
恆 |
恇 |
恈 |
恉 |
恊 |
恋 |
恌 |
恍 |
恎 |
恏 |
6050 |
恐 |
恑 |
恒 |
恓 |
恔 |
恕 |
恖 |
恗 |
恘 |
恙 |
恚 |
恛 |
恜 |
恝 |
恞 |
恟 |
6060 |
恠 |
恡 |
恢 |
恣 |
恤 |
恥 |
恦 |
恧 |
恨 |
恩 |
恪 |
恫 |
恬 |
恭 |
恮 |
息 |
6070 |
恰 |
恱 |
恲 |
恳 |
恴 |
恵 |
恶 |
恷 |
恸 |
恹 |
恺 |
恻 |
恼 |
恽 |
恾 |
恿 |
6080 |
悀 |
悁 |
悂 |
悃 |
悄 |
悅 |
悆 |
悇 |
悈 |
悉 |
悊 |
悋 |
悌 |
悍 |
悎 |
悏 |
6090 |
悐 |
悑 |
悒 |
悓 |
悔 |
悕 |
悖 |
悗 |
悘 |
悙 |
悚 |
悛 |
悜 |
悝 |
悞 |
悟 |
60A0 |
悠 |
悡 |
悢 |
患 |
悤 |
悥 |
悦 |
悧 |
您 |
悩 |
悪 |
悫 |
悬 |
悭 |
悮 |
悯 |
60B0 |
悰 |
悱 |
悲 |
悳 |
悴 |
悵 |
悶 |
悷 |
悸 |
悹 |
悺 |
悻 |
悼 |
悽 |
悾 |
悿 |
60C0 |
惀 |
惁 |
惂 |
惃 |
惄 |
情 |
惆 |
惇 |
惈 |
惉 |
惊 |
惋 |
惌 |
惍 |
惎 |
惏 |
60D0 |
惐 |
惑 |
惒 |
惓 |
惔 |
惕 |
惖 |
惗 |
惘 |
惙 |
惚 |
惛 |
惜 |
惝 |
惞 |
惟 |
60E0 |
惠 |
惡 |
惢 |
惣 |
惤 |
惥 |
惦 |
惧 |
惨 |
惩 |
惪 |
惫 |
惬 |
惭 |
惮 |
惯 |
60F0 |
惰 |
惱 |
惲 |
想 |
惴 |
惵 |
惶 |
惷 |
惸 |
惹 |
惺 |
惻 |
惼 |
惽 |
惾 |
惿 |
GB18030-2000 is a new character set standard from the PRC that specifies an extended codepage and a mapping table to Unicode.
On March 17, 2000, the Chinese government issued regulations mandating that all operating systems on non-handheld computers sold in the PRC after January 1, 2001 would have to comply with the new multibyte GB18030-2000 standard. However, the initial implementation deadline of January 1, 2001 was later postponed until September 1, 2001.
Evolution of GB18030-2000
All character set standards that originate in the PRC have designations that begin with "GB". GB is an abbreviation for Guojia Biaozhun, meaning "national standard". The GB 2312-1980 character set standard was established in 1981 to represent simplified Chinese characters. GB 2312-1980 is a coded character set that contains 7,445 characters, including 6,763 Hanzi and 682 non-Hanzi characters. With the release of ISO 10646-1/Unicode 2.1 in 1993, the PRC expressed its fundamental consent to support the combined efforts of the ISO/IEC and the Unicode Consortium through publishing a Chinese National Standard that was code- and character-compatible with ISO 10646-1/Unicode 2.1. This standard was named GB 13000.1. Whenever the ISO and the Unicode Consortium changed or revised their common standard, GB 13000.1 subsequently adopted these changes.
To accommodate all additional Hanzi characters specified in GB 13000.1 that are not included in GB 2312-1980, a new specification known as GBK was then introduced. GBK is an abbreviation for "Guojia biaozhun kuozhan", which is the Chinese for "Rules/Specifications defining the extensions of internal codes for Chinese ideograms". GBK is an extension of GB 2312-1980 and the key significant property of GBK is that it leaves the characters and codes as defined in GB 2312-1980 untouched and positions all additional characters around it. The additional characters are mainly those of the Unified Han portion of Unicode 2.1 that go beyond the character repertoire of GB 2312-1980. Thus, code and character compatibility between GBK and GB 2312-1980 is ensured while, at the same time, the complete Unicode Unified Han character set is made available. At the time when GBK was defined, other characters were added that were not available in Unicode.
GBK defines 23,940 code points containing 21,886 characters. At the same time, GBK provides mappings to the code points of Unicode 2.1. However, due to the packed code space used to define GBK, it became obvious that there was no space left for a major addition. The 1,894 code points of GBK‘s three user-defined areas were not even close to providing sufficient space for the CJK Unified Ideographs Extension A, which defines 6,582 new characters in plane 0 of Unicode, version 3.0, the Basic Multilingual Plane (BMP).
Therefore, GB18030-2000 was created as an update of GBK for Unicode 3.0 with an extension that covers all of Unicode. It is fully backward-compatible with GB 2312-1980 and GBK. The mapping table from GB18030-2000 to Unicode is backward-compatible with the mapping table from GB 2312-1980 to Unicode, however, the GBK to Unicode table has a few differences. GBK contains characters which were not defined in Unicode 2.1, but were added in later versions of Unicode.
GB18030-2000 specifies a mapping table that covers all Unicode code points and maintains compatibility of GB-encoded text with GBK and GB 2312-1980.
GBK Encoding Ranges |
||||||||
range |
byte 1 |
byte 2 |
code points (有多少个值可取) |
Characters (实际采用了多少个code points) |
|
|||
GB 18030 |
GBK 1.0 |
Codepage 936 |
GB 2312 |
|
||||
Level GBK/1 |
A1–A9 |
A1–FE |
846 |
728 |
717 |
702 |
682 |
|
Level GBK/2 |
B0–F7 |
A1–FE |
6,768 |
6,763 |
6,763 |
6,763 |
|
|
Level GBK/3 |
81–A0 |
40–FE except 7F |
6,080 |
6,080 |
6,080 |
|
||
Level GBK/4 |
AA–FE |
40–A0 except 7F |
8,160 |
8,160 |
8,080 |
|
||
Level GBK/5 |
A8–A9 |
40–A0 except 7F |
192 |
166 |
166 |
|
||
user-defined |
AA–AF |
A1–FE |
564 |
|
||||
user-defined |
F8–FE |
A1–FE |
658 |
|
||||
user-defined |
A1–A7 |
40–A0 except 7F |
672 |
|
||||
total: |
23,940 |
21,897 |
21,886 |
21,791 |
7,445 |
|
In graphical form, the following figure shows the space of all 64K possible 2-byte codes. Green and yellow areas are assigned GBK codepoints, red are for user-defined characters. The uncolored areas are invalid byte combinations.
从上面的两个图上可以分厂清晰的看出GB 18030、GBK 1.0、Microsoft Codepage 936、GB 2312这些编码的两个字节覆盖的取值范围。从下面的”Mapping Tables for Character Sets”中,也能看到,一个字节情况下128个gbk取值,还有后面的两个字节的情况,这里是以第一个字节为0x81为例,注意第二个字节的取值是从0x40开始的,0x8100到0x8139这个区间中是没有合法取值的,是空缺的位置。对应上面说到的“The uncolored areas are invalid byte combinations.”
Mapping Tables for Character Sets - GB2312
How to read this chart:
symbol |
|
00 |
01 |
02 |
03 |
04 |
05 |
06 |
07 |
08 |
09 |
0A |
0B |
0C |
0D |
0E |
0F |
00 |
NUL |
STX |
SOT |
ETX |
EOT |
ENQ |
ACK |
BEL |
BS |
HT |
LF |
VT |
FF |
CR |
SOT |
SI |
10 |
DLE |
DC1 |
DC2 |
DC3 |
DC4 |
NAK |
SYN |
ETB |
CAN |
EM |
SUB |
ESC |
FS |
GS |
RS |
US |
20 |
SP |
! |
" |
# |
$ |
% |
& |
‘ |
( |
) |
* |
+ |
, |
- |
. |
/ |
30 |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
: |
; |
< |
= |
> |
? |
40 |
@ |
A |
B |
C |
D |
E |
F |
G |
H |
I |
J |
K |
L |
M |
N |
O |
50 |
P |
Q |
R |
S |
T |
U |
V |
W |
X |
Y |
Z |
[ |
\ |
] |
^ |
_ |
60 |
` |
a |
b |
c |
d |
e |
f |
g |
h |
i |
j |
k |
l |
m |
n |
o |
70 |
p |
q |
r |
s |
t |
u |
v |
w |
x |
y |
z |
{ |
| |
} |
~ |
DEL |
80 |
€ |
|||||||||||||||
90 |
||||||||||||||||
A0 |
||||||||||||||||
B0 |
||||||||||||||||
C0 |
||||||||||||||||
D0 |
||||||||||||||||
E0 |
||||||||||||||||
F0 |
|
|
00 |
01 |
02 |
03 |
04 |
05 |
06 |
07 |
08 |
09 |
0A |
0B |
0C |
0D |
0E |
0F |
40 |
丂 |
丄 |
丅 |
丆 |
丏 |
丒 |
丗 |
丟 |
丠 |
両 |
丣 |
並 |
丩 |
丮 |
丯 |
丱 |
50 |
丳 |
丵 |
丷 |
丼 |
乀 |
乁 |
乂 |
乄 |
乆 |
乊 |
乑 |
乕 |
乗 |
乚 |
乛 |
乢 |
60 |
乣 |
乤 |
乥 |
乧 |
乨 |
乪 |
乫 |
乬 |
乭 |
乮 |
乯 |
乲 |
乴 |
乵 |
乶 |
乷 |
70 |
乸 |
乹 |
乺 |
乻 |
乼 |
乽 |
乿 |
亀 |
亁 |
亂 |
亃 |
亄 |
亅 |
亇 |
亊 |
|
80 |
亐 |
亖 |
亗 |
亙 |
亜 |
亝 |
亞 |
亣 |
亪 |
亯 |
亰 |
亱 |
亴 |
亶 |
亷 |
亸 |
90 |
亹 |
亼 |
亽 |
亾 |
仈 |
仌 |
仏 |
仐 |
仒 |
仚 |
仛 |
仜 |
仠 |
仢 |
仦 |
仧 |
A0 |
仩 |
仭 |
仮 |
仯 |
仱 |
仴 |
仸 |
仹 |
仺 |
仼 |
仾 |
伀 |
伂 |
伃 |
伄 |
伅 |
B0 |
伆 |
伇 |
伈 |
伋 |
伌 |
伒 |
伓 |
伔 |
伕 |
伖 |
伜 |
伝 |
伡 |
伣 |
伨 |
伩 |
C0 |
伬 |
伭 |
伮 |
伱 |
伳 |
伵 |
伷 |
伹 |
伻 |
伾 |
伿 |
佀 |
佁 |
佂 |
佄 |
佅 |
D0 |
佇 |
佈 |
佉 |
佊 |
佋 |
佌 |
佒 |
佔 |
佖 |
佡 |
佢 |
佦 |
佨 |
佪 |
佫 |
佭 |
E0 |
佮 |
佱 |
佲 |
併 |
佷 |
佸 |
佹 |
佺 |
佽 |
侀 |
侁 |
侂 |
侅 |
來 |
侇 |
侊 |
F0 |
侌 |
侎 |
侐 |
侒 |
侓 |
侕 |
侖 |
侘 |
侙 |
侚 |
侜 |
侞 |
侟 |
価 |
侢 |
|
UTF-8 (8-bit UCS/Unicode Transformation Format) is a variable-length character encoding for Unicode. It is able to represent any character in the Unicode standard.
Unicode |
Byte1 |
Byte2 |
Byte3 |
Byte4 |
example |
U+0000–U+007F |
0xxxxxxx |
‘$‘ U+0024 |
|||
U+0080–U+07FF |
110yyyxx |
10xxxxxx |
‘¢‘ U+00A2 |
||
U+0800–U+FFFF |
1110yyyy |
10yyyyxx |
10xxxxxx |
‘€‘ U+20AC |
|
U+10000–U+10FFFF |
11110zzz |
10zzyyyy |
10yyyyxx |
10xxxxxx |
‘??‘ U+024B62 |
In computing, UTF-16 (16-bit UCS/Unicode Transformation Format) is a variable-length character encoding for Unicode, capable of encoding the entire Unicode repertoire.
UCS-2(2-byte Universal Character Set) The UCS-2 encoding form is identical to that of UTF-16, except that it does not support surrogate pairs and therefore can only encode characters in the BMP range U+0000 through U+FFFF.
The improvement that UTF-16 made over UCS-2 is its ability to encode characters in planes 1–16, not just those in plane 0 (BMP). This was done by taking an unassigned portion of the 16 bit UCS-2 space, shown to scale by color here:
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
注意:在上面的BMP(mapping of Unicode character planes)中0xD8到0xF8都是“utf-16 surrogates and private use”,这里的前面8个区域就是用来支持utf-16表示BMP以外的unicode编码用的。
|
DC00 |
DC01 |
… |
DFFF |
D800 |
010000 |
010001 |
… |
0103FF |
D801 |
010400 |
010401 |
… |
0107FF |
? |
? |
? |
||
DBFF |
10FC00 |
10FC01 |
… |
10FFFF |
UTF-16 represents non-BMP characters (those from U+10000 through U+10FFFF) using a pair of 16-bit words, known as a surrogate pair. First 1000016 is subtracted from the code point to give a 20-bit value. This is then split into two separate 10-bit values each of which is represented as a surrogate with the most significant half placed in the first surrogate. To allow safe use of simple word-oriented string processing, separate ranges of values are used for the two surrogates: 0xD800–0xDBFF for the first, most significant surrogate (marked brown) and 0xDC00-0xDFFF for the second, least significant surrogate (marked azure).
For example, the character at code point U+10000 becomes the code unit sequence 0xD800 0xDC00, and the character at U+10FFFD, the upper limit of Unicode, becomes the sequence 0xDBFF 0xDFFD.[Chandler2] Unicode and ISO/IEC 10646 do not, and will never, assign characters to any of the code points in the U+D800–U+DFFF range, so an individual code value from a surrogate pair does not ever represent a character.
[Chandler2]U+10FFFD减去0x10000得到0xFFFFD,分成两个10bits的half,第一个是0x3FF,第二个是0x3FD,最终:
1st surrogate:0xD800+0x3FF=0xDBFF
2nd surrogate:0xDFFD+0x3FD=0xFFFD
原文:http://www.cnblogs.com/root-wang/p/3884819.html