fix(core): Updates slice with range selectors (#583)
- [X] Replaces Span slicing with range selection - [X] Replaces string slicing with range selection
This commit is contained in:
parent
9f9d990f85
commit
a0893b68c0
62 changed files with 363 additions and 382 deletions
|
|
@ -81,17 +81,17 @@ namespace Server.Items
|
|||
{
|
||||
if (format.StartsWithOrdinal("the head of "))
|
||||
{
|
||||
format = format.Substring(14); // "the head of|..."
|
||||
format = format[14..]; // "the head of|..."
|
||||
}
|
||||
|
||||
if (format.EndsWithOrdinal(", taken in a duel"))
|
||||
{
|
||||
format = format.Substring(0, format.Length - ", taken in a duel".Length);
|
||||
format = format[..^", taken in a duel".Length];
|
||||
HeadType = HeadType.Duel;
|
||||
}
|
||||
else if (format.EndsWithOrdinal(", taken in a tournament"))
|
||||
{
|
||||
format = format.Substring(0, format.Length - ", taken in a tournament".Length);
|
||||
format = format[..^", taken in a tournament".Length];
|
||||
HeadType = HeadType.Tournament;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ namespace Server.Network
|
|||
|
||||
// We are ok with the string being cut-off mid character. The alternative is very slow.
|
||||
var byteLength = Math.Min(29, TextEncoding.UTF8.GetBytes(textChars, textBuffer));
|
||||
writer.Write(textBuffer.SliceToLength(byteLength));
|
||||
writer.Write(textBuffer[..byteLength]);
|
||||
writer.Clear(30 - byteLength); // terminator
|
||||
|
||||
ns.Send(writer.Span);
|
||||
|
|
@ -281,7 +281,7 @@ namespace Server.Network
|
|||
var tail = pad ? 2 : 1;
|
||||
var length = Math.Min(pad ? 253 : 254, text.GetBytesUtf8(buffer));
|
||||
writer.Write((byte)(length + tail));
|
||||
writer.Write(buffer.SliceToLength(length));
|
||||
writer.Write(buffer[..length]);
|
||||
|
||||
if (pad)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ namespace Server.Items
|
|||
|
||||
if (text.Length > 40)
|
||||
{
|
||||
text = text.Substring(0, 40);
|
||||
text = text[..40];
|
||||
}
|
||||
|
||||
var guild = new Guild(from, text, "none");
|
||||
|
|
|
|||
|
|
@ -39,15 +39,15 @@ namespace Server.Items
|
|||
if (ns.StygianAbyss)
|
||||
{
|
||||
length = OutgoingEntityPackets.CreateWorldEntity(buffer, this, ns.HighSeas);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(buffer[8..10], GMItemId);
|
||||
}
|
||||
else
|
||||
{
|
||||
length = OutgoingItemPackets.CreateWorldItem(buffer, this);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(7, 2), GMItemId);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(buffer[7..9], GMItemId);
|
||||
}
|
||||
|
||||
ns.Send(buffer.SliceToLength(length));
|
||||
ns.Send(buffer[..length]);
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
|
|
|
|||
|
|
@ -45,15 +45,15 @@ namespace Server.Items
|
|||
if (ns.StygianAbyss)
|
||||
{
|
||||
length = OutgoingEntityPackets.CreateWorldEntity(buffer, this, ns.HighSeas);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(buffer[8..10], GMItemId);
|
||||
}
|
||||
else
|
||||
{
|
||||
length = OutgoingItemPackets.CreateWorldItem(buffer, this);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(7, 2), GMItemId);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(buffer[7..2], GMItemId);
|
||||
}
|
||||
|
||||
ns.Send(buffer.SliceToLength(length));
|
||||
ns.Send(buffer[..length]);
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ namespace Server.Items
|
|||
|
||||
if (text.Length > 255)
|
||||
{
|
||||
text = text.Substring(0, 255);
|
||||
text = text[..255];
|
||||
}
|
||||
|
||||
if (text.Length > 0)
|
||||
|
|
@ -316,7 +316,7 @@ namespace Server.Items
|
|||
|
||||
if (text.Length > 255)
|
||||
{
|
||||
text = text.Substring(0, 255);
|
||||
text = text[..255];
|
||||
}
|
||||
|
||||
if (text.Length > 0)
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ namespace Server.Items
|
|||
else
|
||||
{
|
||||
m_Target.EngravedText =
|
||||
Utility.FixHtml(relay.Text.Length > 64 ? relay.Text.Substring(0, 64) : relay.Text);
|
||||
Utility.FixHtml(relay.Text.Length > 64 ? relay.Text[..64] : relay.Text);
|
||||
state.Mobile.SendLocalizedMessage(1072361); // You engraved the object.
|
||||
m_Target.InvalidateProperties();
|
||||
m_Tool.UsesRemaining -= 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue