Rune.DecodeFromUtf16(ReadOnlySpan<Char>, Rune, Int32) Method

Definition

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

public:
 static System::Buffers::OperationStatus DecodeFromUtf16(ReadOnlySpan<char> source, [Runtime::InteropServices::Out] System::Text::Rune % result, [Runtime::InteropServices::Out] int % charsConsumed);
public static System.Buffers.OperationStatus DecodeFromUtf16 (ReadOnlySpan<char> source, out System.Text.Rune result, out int charsConsumed);
static member DecodeFromUtf16 : ReadOnlySpan<char> * Rune * int -> System.Buffers.OperationStatus
Public Shared Function DecodeFromUtf16 (source As ReadOnlySpan(Of Char), ByRef result As Rune, ByRef charsConsumed As Integer) As OperationStatus

Parameters

source
ReadOnlySpan<Char>

A read-only UTF-16 character span.

result
Rune

When this method returns, the decoded rune.

charsConsumed
Int32

When this method returns, the number of characters read to create the rune.

Returns

Done if the source buffer begins with a valid UTF-16 encoded scalar value. result then contains the decoded Rune, and charsConsumed contains the number of Char values used in the input buffer to encode the Rune.

NeedMoreData if the source buffer is empty or contains only a standalone UTF-16 high surrogate character. result then contains ReplacementChar, and charsConsumed contains the length of the input buffer.

InvalidData if the source buffer begins with an ill-formed UTF-16 encoded scalar value. result then contains ReplacementChar, and charsConsumed contains the number of Char values used to encode the ill-formed sequence. .

Remarks

The general convention is to call this method in a loop, slicing the source buffer by charsConsumed elements on each iteration of the loop. On each iteration of the loop, result contains the real scalar value if the data was successfully decoded, or it contains Rune.ReplacementChar if the data was not successfully decoded. This pattern provides convenient automatic U+FFFD substitution of invalid sequences while iterating through the loop.

Applies to