Edit

Share via


Rune.DecodeFromUtf8(ReadOnlySpan<Byte>, Rune, Int32) Method

Definition

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

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

Parameters

source
ReadOnlySpan<Byte>

A read-only UTF-8 encoded byte span.

result
Rune

When this method returns, the decoded rune.

bytesConsumed
Int32

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

Returns

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

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

InvalidData if the source buffer begins with an ill-formed UTF-8 encoded scalar value. result then contains ReplacementChar, and bytesConsumed contains the number of Byte values used in the input buffer to encode the ill-formed sequence. .

Remarks

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

Applies to