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
-
objectStringMarshal
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
sourcebyte*The pointer to a null-terminated ASCII character sequence.
maxLengthintThe maxmimum length of
sourceor-1if the maximum length is unknown.
Returns
- ReadOnlySpan<byte>
A ReadOnlySpan<T> that starts at
sourceand extends tomaxLengthor 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
sourcebyteThe reference to a null-terminated ASCII character sequence.
maxLengthintThe maxmimum length of
sourceor-1if the maximum length is unknown.
Returns
- ReadOnlySpan<byte>
A ReadOnlySpan<T> that starts at
sourceand extends tomaxLengthor 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
sourcestringThe 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
ptrbyte*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
ptrchar*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
spanReadOnlySpan<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
spanReadOnlySpan<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
spanReadOnlySpan<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
sourcestringThe 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
sourceushort*The pointer to a null-terminated UTF-16 string.
maxLengthintThe maxmimum length of
sourceor-1if the maximum length is unknown.
Returns
- ReadOnlySpan<ushort>
A ReadOnlySpan<T> that starts at
sourceand extends tomaxLengthor 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
sourceushortThe reference to a null-terminated UTF-16 string.
maxLengthintThe maxmimum length of
sourceor-1if the maximum length is unknown.
Returns
- ReadOnlySpan<ushort>
A ReadOnlySpan<T> that starts at
sourceand extends tomaxLengthor 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
sourcebyte*The pointer to a null-terminated UTF-8 character sequence.
maxLengthintThe maxmimum length of
sourceor-1if the maximum length is unknown.
Returns
- ReadOnlySpan<byte>
A ReadOnlySpan<T> that starts at
sourceand extends tomaxLengthor 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
sourcebyteThe reference to a null-terminated UTF-8 character sequence.
maxLengthintThe maxmimum length of
sourceor-1if the maximum length is unknown.
Returns
- ReadOnlySpan<byte>
A ReadOnlySpan<T> that starts at
sourceand extends tomaxLengthor 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
sourcestringThe 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.