Table of Contents

Method ToReadOnlySpan

Namespace
Ubiquity.NET.InteropHelpers
Assembly
Ubiquity.NET.InteropHelpers.dll

ToReadOnlySpan(bool)

Gets a ReadOnlySpan<T> of bytes for the native encoding of the string

public ReadOnlySpan<byte> ToReadOnlySpan(bool includeTerminator = false)

Parameters

includeTerminator bool

Indicates whether the span includes the terminator character [default: false]

Returns

ReadOnlySpan<byte>

Span for the encoded bytes of the string

Remarks

This will perform conversion if the LazyEncodedString(string, Encoding?) was used to construct this instance and conversion has not yet occurred. Otherwise it will provide the span it was constructed with or a previously converted one.

When passing a string view (pointer+length) then the terminator is not normally included in the length. When passing a string as a null terminated sequence of characters (pointer) then the null terminator is also not normally included in the length. Thus the default behavior is to not include the terminator. If a span that include any allocated space for a terminator is needed then a true value for includeTerminator will result in a span that includes the terminator.