You're already familiar with char
literals such as the following:
Literals of type _Char16_t
look like this:
Here, the literal u'a'
represents a constant integral value whose type is _Char16_t
. The size of the literal constant equals sizeof(_Char16_t)
A literal of type _Char32_t looks like this:
As you can see, u
have different meanings in this context.
To define _Char16_t and _char32_t string literals, use the following prefixes:
const _Char16_t utf16msg= u"hello";
const _Char32_t utf32msg= U"hello";
The type of the literal string u"hello"
is array of n const _Char16_t
and has static storage duration
, where n
is the size of the string as defined as follows: the total number of escape sequences, universal-character-names, and other characters, plus one for the terminating u'\0'
Universal Character Names
Universal character names in the form \unnnn and \Unnnnnnnn contain hexadecimal values of Unicode symbols defined in Annex C of ISO 10646-1. For example, '\u0531' is the universal character name of the first letter in the Armenian codepage. At present, the support of universal character names is implementation-definedsome C++ compilers accept them, while others don't.
A new standard header called <cuchar> will be added to C++, which includes the definitions of the typedefs char16_t and char32_t. If the macro __STDC_UTF_16__ is defined in <cuchar>, values of type _Char16_t shall have UTF-16 encoding, as defined by ISO 10646. Similarly, if the macro __STDC_UTF_32__ is defined in <cuchar>, values of type _Char32_t shall have UTF-32 encoding, as defined by ISO 10646.
The Standard Library will also provide _Char16_t and _Char32_t typedefs, in analogy to the typedefs wstring, wcout, etc., for the following standard classes:
· filebuf, streambuf, streampos, streamoff
· ios, istream, ostream
· fstream, ifstream, ofstream
· stringstream, istringstream, ostringstream
Improvements in the Pipeline
In conclusion, C++ is about to be rid of another major embarrassmentthe lack of native Unicode supportsoon. The said proposal is now being added to the Working Paper, which means that it will be incorporated into C++09. It's time to get ready!