CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
rune.h
1
2#pragma once
3
4#include <system/span.h>
5#include <system/buffers/operation_status.h>
6#include <system/exceptions.h>
7#include <cstdint>
8
9namespace System {
10namespace Text {
11
14struct Rune
15{
16private:
17 static constexpr uint32_t HighSurrogateStart = 0xD800u;
18 static constexpr uint32_t LowSurrogateStart = 0xDC00u;
19 static constexpr uint32_t HighSurrogateRange = 0x3FFu;
20
21 uint32_t _value;
22
23public:
25 ASPOSECPP_SHARED_API Rune();
26
30 ASPOSECPP_SHARED_API Rune(int32_t value);
31
35 ASPOSECPP_SHARED_API Rune(uint32_t value);
36
41 static ASPOSECPP_SHARED_API bool TryCreate(char16_t ch, Rune& result);
42
48 static ASPOSECPP_SHARED_API bool TryCreate(char16_t highSurrogate, char16_t lowSurrogate, Rune& result);
49
55 static ASPOSECPP_SHARED_API Buffers::OperationStatus DecodeFromUtf16(ReadOnlySpan<char16_t> source, Rune& result, int32_t& charsConsumed);
56
62 static ASPOSECPP_SHARED_API Buffers::OperationStatus DecodeFromUtf8(ReadOnlySpan<uint8_t> source, Rune& result, int32_t& bytesConsumed);
63
68 ASPOSECPP_SHARED_API bool TryEncodeToUtf8(Span<uint8_t> destination, int32_t& bytesWritten);
69
70private:
71 static Rune UnsafeCreate(uint32_t scalarValue);
72
73 static Rune ReplacementChar();
74
75 static bool IsAsciiCodePoint(uint32_t value);
76
77 static bool IsInRangeInclusive(uint32_t value, uint32_t lowerBound, uint32_t upperBound);
78
79 static bool IsSurrogateCodePoint(uint32_t value);
80
81 static bool IsHighSurrogateCodePoint(uint32_t value);
82
83 static bool IsValidUnicodeScalar(uint32_t value);
84};
85
86} // namespace Text
87} // namespace System
Forward to use within Span class.
Definition: span.h:415
Represents a contiguous region of arbitrary memory similar to C++20's std::span.
Definition: span.h:375
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
Represents a Unicode scalar value ([ U+0000..U+D7FF ], inclusive; or [ U+E000..U+10FFFF ],...
Definition: rune.h:15
Rune(uint32_t value)
Creates a Rune from the provided Unicode scalar value.
static Buffers::OperationStatus DecodeFromUtf8(ReadOnlySpan< uint8_t > source, Rune &result, int32_t &bytesConsumed)
Decodes the Rune at the beginning of the provided UTF-8 source buffer.
bool TryEncodeToUtf8(Span< uint8_t > destination, int32_t &bytesWritten)
Encodes this Rune to a UTF-8 destination buffer.
static bool TryCreate(char16_t ch, Rune &result)
Attempts to create a Rune from the provided UTF-16 code unit.
Rune(int32_t value)
Creates a Rune from the provided Unicode scalar value.
static Buffers::OperationStatus DecodeFromUtf16(ReadOnlySpan< char16_t > source, Rune &result, int32_t &charsConsumed)
Decodes the Rune at the beginning of the provided UTF-16 source buffer.
static bool TryCreate(char16_t highSurrogate, char16_t lowSurrogate, Rune &result)
Attempts to create a Rune from the provided UTF-16 surrogate pair.
Rune()
Constructs a default Rune representing U+0000.