Utf8String
Namespace Mc.Scripting · Kind struct (readonly, ref)
public readonly ref struct Utf8StringBorrowed UTF-8 string (McStr). Only valid during the call/dispatch that provided it: call Utf8String.ToString to keep a copy.
Remarks
Section titled “Remarks”Event string fields (Message, Username, …) are this type: borrowed UTF-8 memory owned by the engine. Only ToString() and Contains() allocate.
Examples
Section titled “Examples”Reading an event string
Events.On((ref PlayerChatEvent e) =>{ if (e.Message.IsEmpty) return; // no allocation if (e.Message.EqualsAscii("!help"u8)) { /* ... */ } // byte compare, no allocation string copy = e.Message.ToString(); // allocates; safe to keep});Constructors
Section titled “Constructors”| Member | Description |
|---|---|
Utf8String(byte* data, long size) |
Wraps native memory (the engine does this; plugins receive these in events). |
Constructor
Section titled “Constructor”public Utf8String(byte* data, long size)Wraps native memory (the engine does this; plugins receive these in events).
Parameters
| Name | Type | Description |
|---|---|---|
data |
byte* |
|
size |
long |
Properties
Section titled “Properties”| Member | Description |
|---|---|
ReadOnlySpan<byte> Bytes { get; } |
The UTF-8 bytes (borrowed). |
bool IsEmpty { get; } |
Whether the string is empty. |
int Length { get; } |
Length in bytes. |
public ReadOnlySpan<byte> Bytes { get; }The UTF-8 bytes (borrowed).
IsEmpty
Section titled “IsEmpty”public bool IsEmpty { get; }Whether the string is empty.
Length
Section titled “Length”public int Length { get; }Length in bytes.
Methods
Section titled “Methods”| Member | Description |
|---|---|
bool Contains(string text, StringComparison comparison = StringComparison.Ordinal) |
Whether the decoded text contains text (allocates). |
bool EqualsAscii(ReadOnlySpan<byte> utf8) |
Byte-wise equality with an ASCII/UTF-8 literal (no allocation). |
override string ToString() |
Copies the text into a managed string. |
Contains
Section titled “Contains”public bool Contains(string text, StringComparison comparison = StringComparison.Ordinal)Whether the decoded text contains text (allocates).
Parameters
| Name | Type | Description |
|---|---|---|
text |
string |
|
comparison |
StringComparison = StringComparison.Ordinal |
Returns bool
EqualsAscii
Section titled “EqualsAscii”public bool EqualsAscii(ReadOnlySpan<byte> utf8)Byte-wise equality with an ASCII/UTF-8 literal (no allocation).
Parameters
| Name | Type | Description |
|---|---|---|
utf8 |
ReadOnlySpan<byte> |
Returns bool
ToString
Section titled “ToString”public override string ToString()Copies the text into a managed string.
Returns string