diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index 2850a65aa..9c49f0f1f 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -3273,9 +3273,9 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro string suffix = hasTitle switch { - true when hasGuild => $" {Title} [{Utility.FixHtmlFormattable(guild.Abbreviation)}]", + true when hasGuild => $" {Title} [{guild.Abbreviation.FixHtmlFormattable()}]", true => $" {Title}", - false when hasGuild => $" [{Utility.FixHtmlFormattable(guild.Abbreviation)}]", + false when hasGuild => $" [{guild.Abbreviation.FixHtmlFormattable()}]", _ => " " }; @@ -3291,16 +3291,16 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro { if (NewGuildDisplay) { - list.Add($"{Utility.FixHtmlFormattable(guildTitle)}, {Utility.FixHtmlFormattable(guild.Name)}"); + list.Add($"{guildTitle.FixHtmlFormattable()}, {guild.Name.FixHtmlFormattable()}"); } else { - list.Add($"{Utility.FixHtmlFormattable(guildTitle)}, {Utility.FixHtmlFormattable(guild.Name)} Guild{type}"); + list.Add($"{guildTitle.FixHtmlFormattable()}, {guild.Name.FixHtmlFormattable()} Guild{type}"); } } else { - list.Add(Utility.FixHtml(guild.Name)); + list.Add(guild.Name.FixHtml()); } } } diff --git a/Projects/Server/Utilities/Utility.cs b/Projects/Server/Utilities/Utility.cs index 837cd92b5..4af818b93 100644 --- a/Projects/Server/Utilities/Utility.cs +++ b/Projects/Server/Utilities/Utility.cs @@ -22,7 +22,7 @@ public static class Utility private static Dictionary _ipAddressTable; private static SkillName[] _allSkills = - { + [ SkillName.Alchemy, SkillName.Anatomy, SkillName.AnimalLore, @@ -82,19 +82,19 @@ public static class Utility // SkillName.Mysticism, // SkillName.Imbuing, SkillName.Throwing - }; + ]; private static readonly SkillName[] m_CombatSkills = - { + [ SkillName.Archery, SkillName.Swords, SkillName.Macing, SkillName.Fencing, SkillName.Wrestling - }; + ]; private static readonly SkillName[] m_CraftSkills = - { + [ SkillName.Alchemy, SkillName.Blacksmith, SkillName.Fletching, @@ -104,7 +104,7 @@ public static class Utility SkillName.Inscribe, SkillName.Tailoring, SkillName.Tinkering - }; + ]; private static readonly Stack m_ConsoleColors = new(); @@ -280,40 +280,51 @@ public static class Utility return ip >= min && ip <= max; } - public static string FixHtml(string str) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string FixHtml(this string str) => ((ReadOnlySpan)str).FixHtml(); + + public static string FixHtml(this ReadOnlySpan str) { - if (string.IsNullOrEmpty(str)) + if (str.IsNullOrWhiteSpace()) { - return str; + return str.ToString(); } - var chars = str.ToPooledArray(); + var chars = STArrayPool.Shared.Rent(str.Length); var span = chars.AsSpan(0, str.Length); + str.CopyTo(span); + FixHtml(span); - return span.ToString(); + var fixedStr = span.ToString(); + STArrayPool.Shared.Return(chars); + return fixedStr; } - public static void FixHtml(Span chars) + public static void FixHtml(this Span chars) { if (chars.Length == 0) { return; } - ReadOnlySpan invalid = stackalloc []{ '<', '>', '#' }; - ReadOnlySpan replacement = stackalloc []{ '(', ')', '-' }; + ReadOnlySpan invalid = ['<', '>', '#']; + ReadOnlySpan replacement = ['(', ')', '-']; chars.ReplaceAny(invalid, replacement); } - public static PooledArraySpanFormattable FixHtmlFormattable(string str) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static PooledArraySpanFormattable FixHtmlFormattable(this string str) => + ((ReadOnlySpan)str).FixHtmlFormattable(); + + public static PooledArraySpanFormattable FixHtmlFormattable(this ReadOnlySpan str) { - var chars = str.ToPooledArray(); + var chars = STArrayPool.Shared.Rent(str.Length); var span = chars.AsSpan(0, str.Length); var formattable = new PooledArraySpanFormattable(chars, str.Length); - if (!string.IsNullOrEmpty(str)) + if (!str.IsNullOrWhiteSpace()) { FixHtml(span); } @@ -321,10 +332,6 @@ public static class Utility return formattable; } - public static int InsensitiveCompare(string first, string second) => first.InsensitiveCompare(second); - - public static bool InsensitiveStartsWith(string first, string second) => first.InsensitiveStartsWith(second); - public static Direction GetDirection(Point3D from, Point3D to) => GetDirection(from.X, from.Y, to.X, to.Y); public static Direction GetDirection(Point2D from, Point2D to) => GetDirection(from.X, from.Y, to.X, to.Y); @@ -793,7 +800,7 @@ public static class Utility { if (count <= 0) { - return new List(); + return []; } var length = source.Count; @@ -1225,14 +1232,14 @@ public static class Utility [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Add(ref List list, T value) { - list ??= new List(); + list ??= []; list.Add(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Add(ref HashSet set, T value) { - set ??= new HashSet(); + set ??= []; set.Add(value); } @@ -1504,8 +1511,7 @@ public static class Utility }; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsNullOrWhiteSpace(this ReadOnlySpan span) => - span == default || span.IsEmpty || span.IsWhiteSpace(); + public static bool IsNullOrWhiteSpace(this ReadOnlySpan span) => span.IsEmpty || span.IsWhiteSpace(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool InTypeList(this T obj, Type[] types) => obj.GetType().InTypeList(types); diff --git a/Projects/UOContent/Commands/Batch.cs b/Projects/UOContent/Commands/Batch.cs index 8b4ce4a25..c47219b78 100644 --- a/Projects/UOContent/Commands/Batch.cs +++ b/Projects/UOContent/Commands/Batch.cs @@ -158,7 +158,7 @@ namespace Server.Commands return false; } - if (Condition.Length > 0 && !Utility.InsensitiveStartsWith(Condition, "where")) + if (Condition.Length > 0 && !Condition.InsensitiveStartsWith("where")) { from.SendMessage("The condition field must start with \"where\"."); return false; diff --git a/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs b/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs index 23f6587c5..26b860ea9 100644 --- a/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs +++ b/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs @@ -287,7 +287,7 @@ public partial class BulkOrderBook : Item, ISecurable if (from.CheckAlive() && m_Book.IsChildOf(from.Backpack)) { - m_Book.BookName = Utility.FixHtml(text.Trim()); + m_Book.BookName = text.Trim().FixHtml(); from.SendLocalizedMessage(1062480); // The bulk order book's name has been changed. } diff --git a/Projects/UOContent/Engines/Help/PageQueue.cs b/Projects/UOContent/Engines/Help/PageQueue.cs index 67d6816b7..6a248f857 100644 --- a/Projects/UOContent/Engines/Help/PageQueue.cs +++ b/Projects/UOContent/Engines/Help/PageQueue.cs @@ -34,7 +34,7 @@ namespace Server.Engines.Help { Sender = sender; Sent = Core.Now; - Message = Utility.FixHtml(message); + Message = message.FixHtml(); Type = type; PageLocation = sender.Location; PageMap = sender.Map; diff --git a/Projects/UOContent/Engines/Help/SpeechLogGump.cs b/Projects/UOContent/Engines/Help/SpeechLogGump.cs index e9668a2a6..cfcfbb3ef 100644 --- a/Projects/UOContent/Engines/Help/SpeechLogGump.cs +++ b/Projects/UOContent/Engines/Help/SpeechLogGump.cs @@ -46,7 +46,7 @@ namespace Server.Engines.Help 10, 280, 20, - $"
SPEECH LOG - {playerName} ({Utility.FixHtmlFormattable(playerAccount)})
" + $"
SPEECH LOG - {playerName} ({playerAccount.FixHtmlFormattable()})
" ); var lastPage = (log.Count - 1) / MaxEntriesPerPage; @@ -82,8 +82,8 @@ namespace Server.Engines.Help builder.AppendFormat( "{0} ({1}): {2}", name, - Utility.FixHtml(account), - Utility.FixHtml(speech) + account.FixHtml(), + speech.FixHtml() ); } diff --git a/Projects/UOContent/Gumps/Guilds/New Guild System/CreateGuildGump.cs b/Projects/UOContent/Gumps/Guilds/New Guild System/CreateGuildGump.cs index 5d6729e97..a24787e32 100644 --- a/Projects/UOContent/Gumps/Guilds/New Guild System/CreateGuildGump.cs +++ b/Projects/UOContent/Gumps/Guilds/New Guild System/CreateGuildGump.cs @@ -53,8 +53,8 @@ namespace Server.Guilds { case 1: { - var guildName = Utility.FixHtml(info.GetTextEntry(5) ?? ""); - var guildAbbrev = Utility.FixHtml(info.GetTextEntry(6) ?? ""); + var guildName = (info.GetTextEntry(5) ?? "").FixHtml(); + var guildAbbrev = (info.GetTextEntry(6) ?? "").FixHtml(); if (guildName.Length <= 0) { diff --git a/Projects/UOContent/Gumps/Guilds/New Guild System/GuildInfoGump.cs b/Projects/UOContent/Gumps/Guilds/New Guild System/GuildInfoGump.cs index c9f146e70..55c1f86c8 100644 --- a/Projects/UOContent/Gumps/Guilds/New Guild System/GuildInfoGump.cs +++ b/Projects/UOContent/Gumps/Guilds/New Guild System/GuildInfoGump.cs @@ -173,7 +173,7 @@ namespace Server.Guilds return; } - var charter = Utility.FixHtml(text.Trim()); + var charter = text.Trim().FixHtml(); if (charter.Length > 50) { @@ -193,7 +193,7 @@ namespace Server.Guilds return; } - var site = Utility.FixHtml(text.Trim()); + var site = text.Trim().FixHtml(); if (site.Length > 50) { diff --git a/Projects/UOContent/Gumps/Guilds/New Guild System/GuildMemberInfoGump.cs b/Projects/UOContent/Gumps/Guilds/New Guild System/GuildMemberInfoGump.cs index 1271b3410..5fac2a927 100644 --- a/Projects/UOContent/Gumps/Guilds/New Guild System/GuildMemberInfoGump.cs +++ b/Projects/UOContent/Gumps/Guilds/New Guild System/GuildMemberInfoGump.cs @@ -265,7 +265,7 @@ namespace Server.Guilds return; } - var title = Utility.FixHtml(text.Trim()); + var title = text.Trim().FixHtml(); if (title.Length > 20) { diff --git a/Projects/UOContent/Gumps/Guilds/New Guild System/OtherGuildInfo.cs b/Projects/UOContent/Gumps/Guilds/New Guild System/OtherGuildInfo.cs index 23abda5b5..a923a47b3 100644 --- a/Projects/UOContent/Gumps/Guilds/New Guild System/OtherGuildInfo.cs +++ b/Projects/UOContent/Gumps/Guilds/New Guild System/OtherGuildInfo.cs @@ -677,7 +677,7 @@ namespace Server.Guilds } else { - var name = Utility.FixHtml(text.Trim()); + var name = text.Trim().FixHtml(); if (!CheckProfanity(name)) { diff --git a/Projects/UOContent/Gumps/RunebookGump.cs b/Projects/UOContent/Gumps/RunebookGump.cs index 104f17398..e9422f289 100644 --- a/Projects/UOContent/Gumps/RunebookGump.cs +++ b/Projects/UOContent/Gumps/RunebookGump.cs @@ -480,7 +480,7 @@ namespace Server.Gumps if (m_Book.CheckAccess(from)) { - m_Book.Description = Utility.FixHtml(text.Trim()); + m_Book.Description = text.Trim().FixHtml(); from.CloseGump(); from.SendGump(new RunebookGump(from, m_Book)); diff --git a/Projects/UOContent/Holiday Stuff/Valentine/2011/Items/StValentinesBears.cs b/Projects/UOContent/Holiday Stuff/Valentine/2011/Items/StValentinesBears.cs index 54f284717..e978bcaaf 100644 --- a/Projects/UOContent/Holiday Stuff/Valentine/2011/Items/StValentinesBears.cs +++ b/Projects/UOContent/Holiday Stuff/Valentine/2011/Items/StValentinesBears.cs @@ -175,9 +175,9 @@ namespace Server.Items m_Bear.EditLimit = Core.Now + TimeSpan.FromMinutes(10); } - m_Bear.Line1 = Utility.FixHtml(line1); - m_Bear.Line2 = Utility.FixHtml(line2); - m_Bear.Line3 = Utility.FixHtml(line3); + m_Bear.Line1 = line1.FixHtml(); + m_Bear.Line2 = line2.FixHtml(); + m_Bear.Line3 = line3.FixHtml(); from.SendMessage("You add the personalized greeting to your St. Valentine Bear."); } diff --git a/Projects/UOContent/Items/Books/BookPackets.cs b/Projects/UOContent/Items/Books/BookPackets.cs index 074519670..806b17de2 100644 --- a/Projects/UOContent/Items/Books/BookPackets.cs +++ b/Projects/UOContent/Items/Books/BookPackets.cs @@ -44,8 +44,8 @@ namespace Server.Items var title = reader.ReadAsciiSafe(60); var author = reader.ReadAsciiSafe(30); - book.Title = Utility.FixHtml(title); - book.Author = Utility.FixHtml(author); + book.Title = title.FixHtml(); + book.Author = author.FixHtml(); } public static void HeaderChange(NetState state, SpanReader reader) @@ -80,8 +80,8 @@ namespace Server.Items var author = reader.ReadUTF8Safe(authorLength); - book.Title = Utility.FixHtml(title); - book.Author = Utility.FixHtml(author); + book.Title = title.FixHtml(); + book.Author = author.FixHtml(); } public static void ContentChange(NetState state, SpanReader reader) diff --git a/Projects/UOContent/Items/Guilds/Guildstone.cs b/Projects/UOContent/Items/Guilds/Guildstone.cs index 467b99f85..6c0603984 100644 --- a/Projects/UOContent/Items/Guilds/Guildstone.cs +++ b/Projects/UOContent/Items/Guilds/Guildstone.cs @@ -114,11 +114,11 @@ public partial class Guildstone : Item, IAddon, IChoppable } // list.Add( 1060802, Utility.FixHtml( name ) ); // Guild name: ~1_val~ - list.Add(1060802, $"{Utility.FixHtmlFormattable(name)} [{Utility.FixHtmlFormattable(abbr)}]"); + list.Add(1060802, $"{name.FixHtmlFormattable()} [{abbr.FixHtmlFormattable()}]"); } else if (_guildName != null && _guildAbbrev != null) { - list.Add(1060802, $"{Utility.FixHtmlFormattable(_guildName)} [{Utility.FixHtmlFormattable(_guildAbbrev)}]"); + list.Add(1060802, $"{_guildName.FixHtmlFormattable()} [{_guildAbbrev.FixHtmlFormattable()}]"); } } @@ -254,11 +254,11 @@ public partial class GuildstoneDeed : Item } // list.Add( 1060802, Utility.FixHtml( name ) ); // Guild name: ~1_val~ - list.Add(1060802, $"{Utility.FixHtmlFormattable(name)} [{Utility.FixHtmlFormattable(abbr)}]"); + list.Add(1060802, $"{name.FixHtmlFormattable()} [{abbr.FixHtmlFormattable()}]"); } else if (_guildName != null && _guildAbbrev != null) { - list.Add(1060802, $"{Utility.FixHtmlFormattable(_guildName)} [{Utility.FixHtmlFormattable(_guildAbbrev)}]"); + list.Add(1060802, $"{_guildName.FixHtmlFormattable()} [{_guildAbbrev.FixHtmlFormattable()}]"); } } diff --git a/Projects/UOContent/Items/Misc/Key.cs b/Projects/UOContent/Items/Misc/Key.cs index 5c557c65d..4e16c55c1 100644 --- a/Projects/UOContent/Items/Misc/Key.cs +++ b/Projects/UOContent/Items/Misc/Key.cs @@ -234,7 +234,7 @@ public partial class Key : Item return; } - _key.Description = Utility.FixHtml(text); + _key.Description = text.FixHtml(); } } diff --git a/Projects/UOContent/Items/Special/Veteran Rewards/WeaponEngravingTool.cs b/Projects/UOContent/Items/Special/Veteran Rewards/WeaponEngravingTool.cs index 87b7a4e3f..bffbb5f48 100644 --- a/Projects/UOContent/Items/Special/Veteran Rewards/WeaponEngravingTool.cs +++ b/Projects/UOContent/Items/Special/Veteran Rewards/WeaponEngravingTool.cs @@ -245,7 +245,7 @@ public partial class WeaponEngravingTool : Item, IUsesRemaining, IRewardItem else { _target.EngravedText = - Utility.FixHtml(relay.Length > 64 ? relay[..64] : relay); + (relay.Length > 64 ? relay[..64] : relay).FixHtml(); state.Mobile.SendLocalizedMessage(1072361); // You engraved the object. _target.InvalidateProperties(); _tool.UsesRemaining -= 1; diff --git a/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs b/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs index cc3e707eb..7c3ce7506 100644 --- a/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs +++ b/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs @@ -519,7 +519,7 @@ namespace Server.Mobiles } else { - vi.Description = Utility.FixHtml(vi.Description); + vi.Description = vi.Description.FixHtml(); } } @@ -1451,7 +1451,7 @@ namespace Server.Mobiles description = text.Trim(); } - SetInfo(from, price, Utility.FixHtml(description)); + SetInfo(from, price, description.FixHtml()); } public override void OnCancel(Mobile from) @@ -1590,7 +1590,7 @@ namespace Server.Mobiles return; } - m_Vendor.Name = Utility.FixHtml(name); + m_Vendor.Name = name.FixHtml(); from.SendLocalizedMessage(1062496); // Your vendor has been renamed. @@ -1619,7 +1619,7 @@ namespace Server.Mobiles return; } - m_Vendor.ShopName = Utility.FixHtml(name); + m_Vendor.ShopName = name.FixHtml(); from.SendGump(new NewPlayerVendorOwnerGump(m_Vendor)); } diff --git a/Projects/UOContent/Multis/Houses/BaseHouse.cs b/Projects/UOContent/Multis/Houses/BaseHouse.cs index c6402d7ca..b7637e9b7 100644 --- a/Projects/UOContent/Multis/Houses/BaseHouse.cs +++ b/Projects/UOContent/Multis/Houses/BaseHouse.cs @@ -3739,7 +3739,7 @@ namespace Server.Multis ref ySouth ); - list.Add(1061112, Utility.FixHtml(houseName)); // House Name: ~1_val~ + list.Add(1061112, houseName.FixHtml()); // House Name: ~1_val~ list.Add(1061113, owner); // Owner: ~1_val~ if (valid) { diff --git a/Projects/UOContent/Multis/Houses/HouseSign.cs b/Projects/UOContent/Multis/Houses/HouseSign.cs index d5759bb60..8737b048b 100644 --- a/Projects/UOContent/Multis/Houses/HouseSign.cs +++ b/Projects/UOContent/Multis/Houses/HouseSign.cs @@ -61,7 +61,7 @@ namespace Server.Multis { base.GetProperties(list); - list.Add(1061639, Utility.FixHtml(GetName())); // Name: ~1_NAME~ + list.Add(1061639, GetName().FixHtml()); // Name: ~1_NAME~ list.Add(1061640, Owner?.Owner == null ? "nobody" : Owner.Owner.Name); // Owner: ~1_OWNER~ if (Owner != null)