chapter 3 of C++ Primer Plus 6th - about how to use universal character name

Viewed 52

The original text in c++ primer plus 6th is as follows:

Using universal character names is similar to using escape sequences.A universal character name begins either with \u or \U.The \u form is followed by 8 hexadecimal digits, and the \U form by 16 hexadecimal digits.These digits represent the ISO 10646 code point for the character. (ISO 10646 is an international standard under development that provides numeric codes for a wide range of characters. See “Unicode and ISO 10646,” later in this chapter.)

But it conflicts with my previous point, so I found the following description in the python3 documentation:

In Python source code, specific Unicode code points can be written using the \u escape sequence, which is followed by four hex digits giving the code point. The \U escape sequence is similar, but expects eight hex digits, not four.

So my question is, when I use the \u form, should it be four hexadecimal bits or eight?

1 Answers

Four hex digits after \u, eight after \U. From the C++ standard:

[lex.charset]/2 The universal-character-name construct provides a way to name other characters.

hex-quad:
    hexadecimal-digit hexadecimal-digit hexadecimal-digit hexadecimal-digit
universal-character-name:
    \u hex-quad
    \U hex-quad hex-quad
Related