Ejemplo n.º 1
0
        private unsafe static bool TryWriteEncodedScalarAsNumericEntity(int unicodeScalar, char *buffer, int length, out int numberOfCharactersWritten)
        {
            Debug.Assert(buffer != null && length >= 0);

            if (UnicodeHelpers.IsSupplementaryCodePoint(unicodeScalar))
            {
                // Convert this back to UTF-16 and write out both characters.
                char leadingSurrogate, trailingSurrogate;
                UnicodeHelpers.GetUtf16SurrogatePairFromAstralScalarValue(unicodeScalar, out leadingSurrogate, out trailingSurrogate);
                int leadingSurrogateCharactersWritten;
                if (TryWriteEncodedSingleCharacter(leadingSurrogate, buffer, length, out leadingSurrogateCharactersWritten) &&
                    TryWriteEncodedSingleCharacter(trailingSurrogate, buffer + leadingSurrogateCharactersWritten, length - leadingSurrogateCharactersWritten, out numberOfCharactersWritten)
                    )
                {
                    numberOfCharactersWritten += leadingSurrogateCharactersWritten;
                    return(true);
                }
                else
                {
                    numberOfCharactersWritten = 0;
                    return(false);
                }
            }
            else
            {
                // This is only a single character.
                return(TryWriteEncodedSingleCharacter(unicodeScalar, buffer, length, out numberOfCharactersWritten));
            }
        }
Ejemplo n.º 2
0
 // Writes a scalar value as an JavaScript-escaped character (or sequence of characters).
 private static void WriteEncodedScalarAsNumericEntity(ref Writer writer, uint value)
 {
     if (UnicodeHelpers.IsSupplementaryCodePoint((int)value))
     {
         // Convert this back to UTF-16 and write out both characters.
         char leadingSurrogate, trailingSurrogate;
         UnicodeHelpers.GetUtf16SurrogatePairFromAstralScalarValue((int)value, out leadingSurrogate, out trailingSurrogate);
         WriteEncodedSingleCharacter(ref writer, leadingSurrogate);
         WriteEncodedSingleCharacter(ref writer, trailingSurrogate);
     }
     else
     {
         // This is only a single character.
         WriteEncodedSingleCharacter(ref writer, value);
     }
 }