For each code unit sequence X in S that either
encodes a single character,
is a shift sequence, or
is a sequence of ill-formed code units,
processing is in order as follows:
CE is UTF-8, UTF-16, or UTF-32 and
C corresponds to a Unicode scalar value
whose Unicode property General_Category has a value in the groups
Separator (Z) or Other (C),
as described by UAX #44 of the Unicode Standard, or
CE is UTF-8, UTF-16, or UTF-32 and
C corresponds to a Unicode scalar value
with the Unicode property Grapheme_Extend=Yes
as described by UAX #44 of the Unicode Standard and
C is not immediately preceded in S by
a character P appended to E
without translation to an escape sequence, or
CE is neither UTF-8, UTF-16, nor UTF-32 and
C is one of an implementation-defined set
of separator or non-printable characters
then the sequence \u{hex-digit-sequence}
is appended to E,
where hex-digit-sequence
is the shortest hexadecimal representation
of C using lower-case hexadecimal digits.
Otherwise (X is a sequence of ill-formed code units),
each code unit U is appended to E in order
as the sequence \x{hex-digit-sequence},
where hex-digit-sequence
is the shortest hexadecimal representation of U
using lower-case hexadecimal digits.