F. Unicode®

Objectives

In this chapter you will learn:

• To become familiar with Unicode.

• The mission of the Unicode Consortium

• The design basis of Unicode.

• The three Unicode encoding forms: UTF-8, UTF-16 and UTF-32.

• Characters and glyphs.

• The advantages and disadvantages of using Unicode.

• A brief tour of the Unicode Consortium’s website.

Outline

F.1 Introduction

F.2 Unicode Transformation Formats

F.3 Characters and Glyphs

F.4 Advantages/Disadvantages of Unicode

F.5 Using Unicode

F.6 Character Ranges

F.1. Introduction

The use of inconsistent character encodings (i.e., numeric values associated with characters) when developing global software products causes serious problems because computers process information using numbers. For instance, the character “a” is converted to a numeric value so that a computer can manipulate that piece of data. Many countries and corporations have developed their own encoding systems that are incompatible with the encoding systems of other countries and corporations. For example, the Microsoft Windows operating system assigns the value 0xC0 to the character “A with a grave accent” while the Apple Macintosh operating system assigns that same value to an upside-down question mark. This results in the misrepresentation and possible corruption of data because data is not processed as intended.

In the absence of a widely implemented universal character encoding standard, global software developers had to localize their products extensively before distribution. Localization includes the language translation and cultural adaptation of content. The process of localization usually includes significant modifications to the source code (such as the conversion of numeric values and the underlying assumptions made by programmers), which results in increased costs and delays releasing the software. For example, some English-speaking programmers might design global software products assuming that a single character can be represented by one byte. However, when those products are localized for Asian markets, the programmer’s assumptions are no longer valid, thus the majority, if not the entirety, of the code needs to be rewritten. Localization is necessary with each release of a version. By the time a software product is localized for a particular market, a newer version, which needs to be localized as well, may be ready for distribution. As a result, it is cumbersome and costly to produce and distribute global software products in a market where there is no universal character encoding standard.

In response to this situation, the Unicode Standard, an encoding standard that facilitates the production and distribution of software, was created. The Unicode Standard outlines a specification to produce consistent encoding of the world’s characters and symbols. Software products which handle text encoded in the Unicode Standard need to be localized, but the localization process is simpler and more efficient because the numeric values need not be converted and the assumptions made by programmers about the character encoding are universal. The Unicode Standard is maintained by a non-profit organization called the Unicode Consortium, whose members include Apple, IBM, Microsoft, Oracle, Sun Microsystems, Sybase and many others.

When the Consortium envisioned and developed the Unicode Standard, they wanted an encoding system that was universal, efficient, uniform and unambiguous. A universal encoding system encompasses all commonly used characters. An efficient encoding system allows text files to be parsed easily. A uniform encoding system assigns fixed values to all characters. An unambiguous encoding system represents a given character in a consistent manner. These four terms are referred to as the Unicode Standard design basis.

F.2. Unicode Transformation Formats

Although Unicode incorporates the limited ASCII character set (i.e., a collection of characters), it encompasses a more comprehensive character set. In ASCII each character is represented by a byte containing 0s and 1s. One byte is capable of storing the binary numbers from 0 to 255. Each character is assigned a number between 0 and 255, thus ASCII-based systems can support only 256 characters, a tiny fraction of the world’s characters. Unicode extends the ASCII character set by encoding the vast majority of the world’s characters. The Unicode Standard encodes all of those characters in a uniform numerical space from 0 to 10FFFF hexadecimal. An implementation will express these numbers in one of several transformation formats, choosing the one that best fits the particular application at hand.

Three such formats are in use, called UTF-8, UTF-16 and UTF-32, depending on the size of the units—in bits—being used. UTF-8, a variable width encoding form, requires one to four bytes to express each Unicode character. UTF-8 data consists of 8-bit bytes (sequences of one, two, three or four bytes depending on the character being encoded) and is well suited for ASCII-based systems when there is a predominance of one-byte characters (ASCII represents characters as one-byte). Currently, UTF-8 is widely implemented in UNIX systems and in databases.

The variable width UTF-16 encoding form expresses Unicode characters in units of 16 bits (i.e., as two adjacent bytes, or a short integer in many machines). Most characters of Unicode are expressed in a single 16-bit unit. However, characters with values above FFFF hexadecimal are expressed with an ordered pair of 16-bit units called surrogates. Surrogates are 16-bit integers in the range D800 through DFFF, which are used solely for the purpose of “escaping” into higher numbered characters. Approximately one million characters can be expressed in this manner. Although a surrogate pair requires 32 bits to represent characters, it is space-efficient to use these 16-bit units. Surrogates are rare characters in current implementations. Many string-handling implementations are written in terms of UTF-16. [Note: Details and sample-code for UTF-16 handling are available on the Unicode Consortium website at www.unicode.org.]

Implementations that require significant use of rare characters or entire scripts encoded above FFFF hexadecimal, should use UTF-32, a 32-bit, fixed-width encoding form that usually requires twice as much memory as UTF-16 encoded characters. The major advantage of the fixed-width UTF-32 encoding form is that it uniformly expresses all characters, so it is easy to handle in arrays.

There are few guidelines that state when to use a particular encoding form. The best encoding form to use depends on computer systems and business protocols, not on the data itself. Typically, the UTF-8 encoding form should be used where computer systems and business protocols require data to be handled in 8-bit units, particularly in legacy systems being upgraded because it often simplifies changes to existing programs. For this reason, UTF-8 has become the encoding form of choice on the Internet. Likewise, UTF-16 is the encoding form of choice on Microsoft Windows applications. UTF-32 is likely to become more widely used in the future as more characters are encoded with values above FFFF hexadecimal. Also, UTF-32 requires less sophisticated handling than UTF-16 in the presence of surrogate pairs. Figure F.1 shows the different ways in which the three encoding forms handle character encoding.

Image

Fig. F.1. Correlation between the three encoding forms.

F.3. Characters and Glyphs

The Unicode Standard consists of characters, written components (i.e., alphabetic letters, numerals, punctuation marks, accent marks, etc.) that can be represented by numeric values. Examples of characters include: U+0041 LATIN CAPITAL LETTER A. In the first character representation, U+yyyy is a code value, in which U+ refers to Unicode code values, as opposed to other hexadecimal values. The yyyy represents a four-digit hexadecimal number of an encoded character. Code values are bit combinations that represent encoded characters. Characters are represented using glyphs, various shapes, fonts and sizes for displaying characters. There are no code values for glyphs in the Unicode Standard. Examples of glyphs are shown in Fig. F.2.

Image

Fig. F.2. Various glyphs of the character A.

The Unicode Standard encompasses the alphabets, ideographs, syllabaries, punctuation marks, diacritics, mathematical operators, etc. that comprise the written languages and scripts of the world. A diacritic is a special mark added to a character to distinguish it from another letter or to indicate an accent (e.g., in Spanish, the tilde “~” above the character “n”). Currently, Unicode provides code values for 94,140 character representations, with more than 880,000 code values reserved for future expansion.

F.4. Advantages/Disadvantages of Unicode

The Unicode Standard has several significant advantages that promote its use. One is the impact it has on the performance of the international economy. Unicode standardizes the characters for the world’s writing systems to a uniform model that promotes transferring and sharing data. Programs developed using such a schema maintain their accuracy because each character has a single definition (i.e., a is always U+0061, % is always U+0025). This enables corporations to manage the high demands of international markets by processing different writing systems at the same time. Also, all characters can be managed in an identical manner, thus avoiding any confusion caused by different character code architectures. Moreover, managing data in a consistent manner eliminates data corruption, because data can be sorted, searched and manipulated using a consistent process.

Another advantage of the Unicode Standard is portability (i.e., the ability to execute software on disparate computers or with disparate operating systems). Most operating systems, databases, programming languages and web browsers currently support, or are planning to support, Unicode.

A disadvantage of the Unicode Standard is the amount of memory required by UTF-16 and UTF-32. ASCII character sets are 8 bits in length, so they require less storage than the default 16-bit Unicode character set. However, the double-byte character set (DBCS) and the multi-byte character set (MBCS) that encode Asian characters (ideographs) require two to four bytes, respectively. In such instances, the UTF-16 or the UTF-32 encoding forms may be used with little hindrance on memory and performance.

Another disadvantage of Unicode is that although it includes more characters than any other character set in common use, it does not yet encode all of the world’s written characters. One additional disadvantage of the Unicode Standard is that UTF-8 and UTF-16 are variable width encoding forms, so characters occupy different amounts of memory.

F.5. Using Unicode

The primary use of the Unicode Standard is the Internet—it has become the default encoding system for XML and any language derived from XML such as XHTML. Figure F.3 marks up (as XML) the text “Welcome to Unicode!” in ten different languages: English, French, German, Japanese, Kannada (India), Portuguese, Russian, Spanish, Telugu (India) and Traditional Chinese. [Note: The Unicode Consortium’s website contains a link to code charts that lists the 16-bit Unicode code values.]


 1   <?xml version = "1.0" encoding = "UTF-8"?>
 2
 3   <!-- Fig. F.3: Unicode.xml -->
 4   <!-- Unicode encoding for ten different languages -->
 5
 6   <UnicodeEncodings>
 7
 8      <!-- English -->
 9      <WelcomeNote>
10         &#x0057;&#x0065;&#x006C;&#x0063;&#x006F;&#x006D;&#x0065;
11         &#x0020;
12         &#x0074;&#x006F;
13         &#x0020;
14         Unicode&#x0021;
15      </WelcomeNote>
16
17      <!-- French -->
18      <WelcomeNote>
19         &#x0042;&#x0069;&#x0065;&#x006E;&#x0076;&#x0065;&#x006E;&#x0075;
20         &#x0065;
21         &#x0020;
22         &#x0061;&#x0075;
23         &#x0020;
24         Unicode&#x0021;
25      </WelcomeNote>
26
27      <!-- German -->
28      <WelcomeNote>
29         &#x0057;&#x0069;&#x006C;&#x006B;&#x006F;&#x006D;&#x006D;&#x0065;
30         &#x006E;
31         &#x0020;
32         &#x007A;&#x0075;
33         &#x0020;
34         Unicode&#x0021;
35      </WelcomeNote>
36
37      <!-- Japanese -->
38      <WelcomeNote>
39         Unicode
40         &#x3078;&#x3087;&#x3045;&#x3053;&#x305D;&#x0021;
41      </WelcomeNote>
42
43      <!-- Kannada -->
44      <WelcomeNote>
45         &#x0CB8;&#x0CC1;&#x0CB8;&#x0CCD;&#x0CB5;&#x0C97;&#x0CA4;
46         &#x0020;
47         Unicode&#x0021;
48      </WelcomeNote>
49
50      <!-- Portuguese -->
51      <WelcomeNote>
52         &#x0053;&#x00E9;&#x006A;&#x0061;
53         &#x0020;
54         &#x0042;&#x0065;&#x006D;&#x0076;&#x0069;&#x006E;&#x0064;&#x006F;
55         &#x0020;
56         Unicode&#x0021;
57      </WelcomeNote>
58
59      <!-- Russian -->
60      <WelcomeNote>
61         &#x0414;&#x043E;&#x0431;&#x0440;&#x043E;
62         &#x0020;
63         &#x043F;&#x043E;&#x0436;&#x0430;&#x043B;&#x043E;&#x0432;&#x0430;
64         &#x0442;&#x044A;
65         &#x0020;
66         &#x0432;
67         &#x0020;
68         Unicode&#x0021;
69      </WelcomeNote>
70
71      <!-- Spanish -->
72      <WelcomeNote>
73         &#x0042;&#x0069;&#x0065;&#x006E;&#x0076;&#x0065;&#x006E;&#x0069;
74         &#x0064;&#x0061;
75         &#x0020;
76         &#x0061;
77         &#x0020;
78         Unicode&#x0021;
79      </WelcomeNote>
80
81      <!-- Telugu -->
82      <WelcomeNote>
83         &#x0C38;&#x0C41;&#x0C38;&#x0C3E;&#x0C35;&#x0C17;&#x0C24;&#x0C02;
84         &#x0020;
85         Unicode&#x0021;
86      </WelcomeNote>
87
88      <!-- Traditional Chinese -->
89      <WelcomeNote>
90         &#x6B22;&#x8FCE;
91         &#x4F7F;&#x7528;
92         &#x0020;
93         Unicode&#x0021;
94      </WelcomeNote>
95   </UnicodeEncodings>

Image

Fig. F.3. XML document using Unicode encoding.

Line 1 of the document specifies the XML declaration that contains the Unicode encoding used. A UTF-8 encoding indicates that the document conforms to the form of Unicode that uses sequences of one to four bytes. [Note: This document uses XML entity references to represent characters. Also, UTF-16 and UTF-32 have yet to be supported by Internet Explorer 5.5 and Netscape Communicator 6.] Line 6 defines the root element, UnicodeEncodings, which contains all other elements (e.g., WelcomeNote) in the document. The first WelcomeNote element (lines 9–15) contains the entity references for the English text. The Code Charts page on the Unicode Consortium website contains the code values for the Basic Latin block (or category), which includes the English alphabet. The entity reference on line 10 equates to “Welcome” in basic text. When marking up Unicode characters in XML (or XHTML), the entity reference &#xyyyy; is used, where yyyy represents the hexadecimal Unicode encoding. For example, the letter “W” (in “Welcome”) is denoted by &#x0057;. Lines 11 and 13 contain the entity reference for the space character. The entity reference for the word “to” is on line 12 and the word “Unicode” is on line 14. “Unicode” is not encoded because it is a registered trademark and has no equivalent translation in most languages. Line 14 also contains the &#x0021; notation for the exclamation mark (!).

The remaining WelcomeNote elements (lines 18–94) contain the entity references for the other nine languages. The code values used for the French, German, Portuguese and Spanish text are located in the Basic Latin block, the code values used for the Traditional Chinese text are located in the CJK Unified Ideographs block, the code values used for the Russian text are located in the Cyrillic block, the code values used for the Japanese text are located in the Hiragana block, and the code values used for the Kannada and Telugu texts are located in their respective blocks.

To render Asian characters in a web browser, the proper language files must be installed. For Windows XP and Vista, directions for ensuring that you have the proper language support can be obtained from the Microsoft website at www.microsoft.com. For additional assistance, visit www.unicode.org/help/display_problems.html.

F.6. Character Ranges

The Unicode Standard assigns code values, which range from 0000 (Basic Latin) to E007F (Tags), to the written characters of the world. Currently, there are code values for 94,140 characters. To simplify the search for a character and its associated code value, the Unicode Standard generally groups code values by script and function (i.e., Latin characters are grouped in a block, mathematical operators are grouped in another block, etc.). As a rule, a script is a single writing system that is used for multiple languages (e.g., the Latin script is used for English, French, Spanish, etc.). The Code Charts page on the Unicode Consortium website lists all the defined blocks and their respective code values. Figure F.4 lists some blocks (scripts) from the website and their range of code values.

Image

Fig. F.4. Some character ranges.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.63.87