Table of Contents

Class StringMarshal

Namespace
Stride.Core.UnsafeExtensions
Assembly
Stride.Core.dll

Provides a set of methods to supplement or replace Marshal when operating on strings and spans of characters.

public static class StringMarshal
Inheritance
object
StringMarshal

Methods

GetAsciiSpan(byte*, int)

Gets a span for a null-terminated ASCII character sequence.

public static ReadOnlySpan<byte> GetAsciiSpan(byte* source, int maxLength = -1)

Parameters

source byte*

The pointer to a null-terminated ASCII character sequence.

maxLength int

The maxmimum length of source or -1 if the maximum length is unknown.

Returns

ReadOnlySpan<byte>

A ReadOnlySpan<T> that starts at source and extends to maxLength or the first null character, whichever comes first.

GetAsciiSpan(in byte, int)

Gets a span for a null-terminated ASCII character sequence.

public static ReadOnlySpan<byte> GetAsciiSpan(in byte source, int maxLength = -1)

Parameters

source byte

The reference to a null-terminated ASCII character sequence.

maxLength int

The maxmimum length of source or -1 if the maximum length is unknown.

Returns

ReadOnlySpan<byte>

A ReadOnlySpan<T> that starts at source and extends to maxLength or the first null character, whichever comes first.

GetAsciiSpan(string)

Gets a null-terminated sequence of ASCII characters for a string.

public static ReadOnlySpan<byte> GetAsciiSpan(this string source)

Parameters

source string

The string for which to marshal.

Returns

ReadOnlySpan<byte>

A ReadOnlySpan<T> containing a null-terminated ASCII string that is equivalent to source.

GetString(byte*)

Gets a string for a pointer to a null-terminated string of bytes, assuming an UTF-8 encoding, the current system codepage, or ANSI.

public static string? GetString(byte* ptr)

Parameters

ptr byte*

A pointer to a null-terminated array of 8-bit integers. The integers are interpreted using the current system code page encoding on Windows (referred to as CP_ACP) and as UTF-8 encoding on non-Windows.

Returns

string

A string created from ptr.

GetString(char*)

Gets a string for a pointer to a null-terminated string of characters, assuming an UTF-16 encoding.

public static string? GetString(char* ptr)

Parameters

ptr char*

A pointer to a null-terminated array of 16-bit characters.

Returns

string

A string created from ptr.

GetString(ReadOnlySpan<byte>)

Gets a string for a given span of bytes, assuming an UTF-8 encoding.

public static string? GetString(this ReadOnlySpan<byte> span)

Parameters

span ReadOnlySpan<byte>

The span for which to create the string.

Returns

string

A string created from span.

GetString(ReadOnlySpan<char>)

Gets a string for a given span, assuming an UTF-16 encoding.

public static string? GetString(this ReadOnlySpan<char> span)

Parameters

span ReadOnlySpan<char>

The span for which to create the string.

Returns

string

A string created from span.

GetString(ReadOnlySpan<ushort>)

Gets a string for a given span, assuming an UTF-16 encoding.

public static string? GetString(this ReadOnlySpan<ushort> span)

Parameters

span ReadOnlySpan<ushort>

The span for which to create the string.

Returns

string

A string created from span.

GetUtf16Span(string)

Gets a null-terminated sequence of UTF-16 characters for a string.

public static ReadOnlySpan<ushort> GetUtf16Span(this string source)

Parameters

source string

The string for which to get the null-terminated UTF-16 character sequence.

Returns

ReadOnlySpan<ushort>

A ReadOnlySpan<T> containing a null-terminated UTF-16 string that is equivalent to source.

GetUtf16Span(ushort*, int)

Gets a span for a null-terminated UTF-16 character sequence.

public static ReadOnlySpan<ushort> GetUtf16Span(ushort* source, int maxLength = -1)

Parameters

source ushort*

The pointer to a null-terminated UTF-16 string.

maxLength int

The maxmimum length of source or -1 if the maximum length is unknown.

Returns

ReadOnlySpan<ushort>

A ReadOnlySpan<T> that starts at source and extends to maxLength or the first null character, whichever comes first.

GetUtf16Span(in ushort, int)

Gets a span for a null-terminated UTF-16 character sequence.

public static ReadOnlySpan<ushort> GetUtf16Span(in ushort source, int maxLength = -1)

Parameters

source ushort

The reference to a null-terminated UTF-16 string.

maxLength int

The maxmimum length of source or -1 if the maximum length is unknown.

Returns

ReadOnlySpan<ushort>

A ReadOnlySpan<T> that starts at source and extends to maxLength or the first null character, whichever comes first.

GetUtf8Span(byte*, int)

Gets a span for a null-terminated UTF-8 character sequence.

public static ReadOnlySpan<byte> GetUtf8Span(byte* source, int maxLength = -1)

Parameters

source byte*

The pointer to a null-terminated UTF-8 character sequence.

maxLength int

The maxmimum length of source or -1 if the maximum length is unknown.

Returns

ReadOnlySpan<byte>

A ReadOnlySpan<T> that starts at source and extends to maxLength or the first null character, whichever comes first.

GetUtf8Span(in byte, int)

Gets a span for a null-terminated UTF-8 character sequence.

public static ReadOnlySpan<byte> GetUtf8Span(in byte source, int maxLength = -1)

Parameters

source byte

The reference to a null-terminated UTF-8 character sequence.

maxLength int

The maxmimum length of source or -1 if the maximum length is unknown.

Returns

ReadOnlySpan<byte>

A ReadOnlySpan<T> that starts at source and extends to maxLength or the first null character, whichever comes first.

GetUtf8Span(string)

Gets a null-terminated sequence of UTF-8 characters for a string.

public static ReadOnlySpan<byte> GetUtf8Span(this string source)

Parameters

source string

The string for which to get the null-terminated UTF8 character sequence.

Returns

ReadOnlySpan<byte>

A ReadOnlySpan<T> containing a null-terminated UTF-8 string that is equivalent to source.