System::Text::Encodings::Web::JavaScriptEncoder class

JavaScriptEncoder class

Represents a JavaScript/JSON text encoder used to escape characters that are not safe to embed directly in a JavaScript or JSON string literal.

class JavaScriptEncoder : public System::Object

Methods

MethodDescription
Encode(ReadOnlySpan<char16_t>, Span<char16_t>, int32_t&, int32_t&, bool)Escapes a UTF-16 input span into a UTF-16 destination span.
EncodeUtf8(ReadOnlySpan<uint8_t>, Span<uint8_t>, int32_t&, int32_t&, bool)Escapes a UTF-8 input span into a UTF-8 destination span.
FindFirstCharacterToEncode(const char16_t *, int32_t) constFinds the index of the first UTF-16 character that needs to be escaped.
FindFirstCharacterToEncodeUtf8(ReadOnlySpan<uint8_t>) constFinds the index of the first UTF-8 byte that needs to be escaped.
static get_Default()Returns the shared instance of the default encoder.
explicit JavaScriptEncoder(bool)Constructs an encoder in the default or relaxed mode.

Remarks

Two modes are provided:* the default encoder escapes all non-ASCII characters and HTML-sensitive characters as \uXXXX;

  • the relaxed encoder escapes only the characters that are mandatory for JSON ("\", ‘"’ and control characters) and passes everything else through.

See Also