CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
javascript_encoder.h
1
2#pragma once
3
4#include <system/object.h>
5#include <system/span.h>
6#include <system/buffers/operation_status.h>
7#include <cstdint>
8
9namespace System {
10namespace Text {
11namespace Encodings {
12namespace Web {
13
22{
23public:
26 ASPOSECPP_SHARED_API explicit JavaScriptEncoder(bool relaxed);
27
31
35 ASPOSECPP_SHARED_API int32_t FindFirstCharacterToEncodeUtf8(ReadOnlySpan<uint8_t> utf8Text) const;
36
41 ASPOSECPP_SHARED_API int32_t FindFirstCharacterToEncode(const char16_t* text, int32_t textLength) const;
42
50 ASPOSECPP_SHARED_API Buffers::OperationStatus EncodeUtf8(ReadOnlySpan<uint8_t> utf8Text, Span<uint8_t> destination, int32_t& bytesConsumed, int32_t& bytesWritten, bool isFinalBlock);
51
59 ASPOSECPP_SHARED_API Buffers::OperationStatus Encode(ReadOnlySpan<char16_t> text, Span<char16_t> destination, int32_t& charsConsumed, int32_t& charsWritten, bool isFinalBlock);
60
61private:
62 bool _relaxed;
63
64 bool NeedsEscaping(uint8_t value) const;
65
66 bool NeedsEscaping(char16_t value) const;
67
68 static bool IsHtmlSensitiveOrNonAscii(uint32_t value);
69
70 static bool IsContinuation(uint8_t b);
71
72 static int32_t Utf8SequenceLength(uint8_t b);
73
74 static bool TryDecodeUtf8(ReadOnlySpan<uint8_t> buffer, int32_t start, int32_t length, uint32_t& scalar, int32_t& consumed);
75
76 static int32_t EscapeLengthAscii(uint8_t value);
77
78 static int32_t EscapeLengthScalar(uint32_t scalar);
79
80 static uint8_t HexDigitByte(uint32_t value);
81
82 static char16_t HexDigitChar(uint32_t value);
83
84 static void EscapeAsciiUtf8(uint8_t value, Span<uint8_t> destination, int32_t& di);
85
86 static void EscapeScalarUtf8(uint32_t scalar, Span<uint8_t> destination, int32_t& di);
87
88 static void WriteHexUtf8(uint32_t value, Span<uint8_t> destination, int32_t& di);
89
90 static void EscapeScalarUtf16(uint32_t scalar, Span<char16_t> destination, int32_t& di);
91
92 static void WriteHexUtf16(uint32_t value, Span<char16_t> destination, int32_t& di);
93};
94
95} // namespace Web
96} // namespace Encodings
97} // namespace Text
98} // namespace System
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Represents a contiguous region of arbitrary memory similar to C++20's std::span.
Definition: span.h:375
Represents a JavaScript/JSON text encoder used to escape characters that are not safe to embed direct...
Definition: javascript_encoder.h:22
int32_t FindFirstCharacterToEncode(const char16_t *text, int32_t textLength) const
Finds the index of the first UTF-16 character that needs to be escaped.
Buffers::OperationStatus EncodeUtf8(ReadOnlySpan< uint8_t > utf8Text, Span< uint8_t > destination, int32_t &bytesConsumed, int32_t &bytesWritten, bool isFinalBlock)
Escapes a UTF-8 input span into a UTF-8 destination span.
int32_t FindFirstCharacterToEncodeUtf8(ReadOnlySpan< uint8_t > utf8Text) const
Finds the index of the first UTF-8 byte that needs to be escaped.
Buffers::OperationStatus Encode(ReadOnlySpan< char16_t > text, Span< char16_t > destination, int32_t &charsConsumed, int32_t &charsWritten, bool isFinalBlock)
Escapes a UTF-16 input span into a UTF-16 destination span.
JavaScriptEncoder(bool relaxed)
Constructs an encoder in the default or relaxed mode.
static System::SharedPtr< JavaScriptEncoder > get_Default()
Returns the shared instance of the default encoder.
OperationStatus
Represents the status of an operation that processes a buffer.
Definition: operation_status.h:11
@ Text
Defines color adjustment information for text.
Definition: db_command.h:9