CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
System::Text::Rune Struct Reference

Represents a Unicode scalar value ([ U+0000..U+D7FF ], inclusive; or [ U+E000..U+10FFFF ], inclusive). It should be allocated on stack and passed to functions by value or by reference. More...

#include <rune.h>

Public Member Functions

 Rune ()
 Constructs a default Rune representing U+0000. More...
 
 Rune (int32_t value)
 Creates a Rune from the provided Unicode scalar value. More...
 
 Rune (uint32_t value)
 Creates a Rune from the provided Unicode scalar value. More...
 
bool TryEncodeToUtf8 (Span< uint8_t > destination, int32_t &bytesWritten)
 Encodes this Rune to a UTF-8 destination buffer. More...
 

Static Public Member Functions

static bool TryCreate (char16_t ch, Rune &result)
 Attempts to create a Rune from the provided UTF-16 code unit. More...
 
static bool TryCreate (char16_t highSurrogate, char16_t lowSurrogate, Rune &result)
 Attempts to create a Rune from the provided UTF-16 surrogate pair. More...
 
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. More...
 
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. More...
 

Detailed Description

Represents a Unicode scalar value ([ U+0000..U+D7FF ], inclusive; or [ U+E000..U+10FFFF ], inclusive). It should be allocated on stack and passed to functions by value or by reference.

Constructor & Destructor Documentation

◆ Rune() [1/3]

System::Text::Rune::Rune ( )

Constructs a default Rune representing U+0000.

◆ Rune() [2/3]

System::Text::Rune::Rune ( int32_t  value)

Creates a Rune from the provided Unicode scalar value.

Parameters
valueThe scalar value to wrap.
Exceptions
ArgumentOutOfRangeExceptionif the value does not represent a valid Unicode scalar value.

◆ Rune() [3/3]

System::Text::Rune::Rune ( uint32_t  value)

Creates a Rune from the provided Unicode scalar value.

Parameters
valueThe scalar value to wrap.
Exceptions
ArgumentOutOfRangeExceptionif the value does not represent a valid Unicode scalar value.

Member Function Documentation

◆ DecodeFromUtf16()

static Buffers::OperationStatus System::Text::Rune::DecodeFromUtf16 ( ReadOnlySpan< char16_t >  source,
Rune &  result,
int32_t &  charsConsumed 
)
static

Decodes the Rune at the beginning of the provided UTF-16 source buffer.

Parameters
sourceThe buffer to decode from.
resultThe decoded Rune, or the replacement character if the data is ill-formed.
charsConsumedThe number of code units consumed from the source buffer.
Returns
The status of the decoding operation.

◆ DecodeFromUtf8()

static Buffers::OperationStatus System::Text::Rune::DecodeFromUtf8 ( ReadOnlySpan< uint8_t >  source,
Rune &  result,
int32_t &  bytesConsumed 
)
static

Decodes the Rune at the beginning of the provided UTF-8 source buffer.

Parameters
sourceThe buffer to decode from.
resultThe decoded Rune, or the replacement character if the data is ill-formed.
bytesConsumedThe number of bytes consumed from the source buffer.
Returns
The status of the decoding operation.

◆ TryCreate() [1/2]

static bool System::Text::Rune::TryCreate ( char16_t  ch,
Rune &  result 
)
static

Attempts to create a Rune from the provided UTF-16 code unit.

Parameters
chThe code unit to convert.
resultThe resulting Rune if the input is not a surrogate.
Returns
true if the code unit represents a valid scalar value; otherwise, false.

◆ TryCreate() [2/2]

static bool System::Text::Rune::TryCreate ( char16_t  highSurrogate,
char16_t  lowSurrogate,
Rune &  result 
)
static

Attempts to create a Rune from the provided UTF-16 surrogate pair.

Parameters
highSurrogateThe high surrogate code unit.
lowSurrogateThe low surrogate code unit.
resultThe resulting Rune if the input represents a valid surrogate pair.
Returns
true if the input represents a well-formed UTF-16 surrogate pair; otherwise, false.

◆ TryEncodeToUtf8()

bool System::Text::Rune::TryEncodeToUtf8 ( Span< uint8_t >  destination,
int32_t &  bytesWritten 
)

Encodes this Rune to a UTF-8 destination buffer.

Parameters
destinationThe buffer to which to write this value as UTF-8.
bytesWrittenThe number of bytes written to the destination buffer, or 0 if the buffer is too small.
Returns
true if the value was written to the buffer; otherwise, false.