fix: Cleans up FixHtml (#1757)

This commit is contained in:
Kamron Batman 2024-05-03 21:24:31 -07:00 committed by GitHub
parent af67c48621
commit becd7aad05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 69 additions and 63 deletions

View file

@ -3273,9 +3273,9 @@ public partial class Mobile : IHued, IComparable<Mobile>, 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<Mobile>, 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());
}
}
}

View file

@ -22,7 +22,7 @@ public static class Utility
private static Dictionary<IPAddress, IPAddress> _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<ConsoleColor> 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<char>)str).FixHtml();
public static string FixHtml(this ReadOnlySpan<char> str)
{
if (string.IsNullOrEmpty(str))
if (str.IsNullOrWhiteSpace())
{
return str;
return str.ToString();
}
var chars = str.ToPooledArray();
var chars = STArrayPool<char>.Shared.Rent(str.Length);
var span = chars.AsSpan(0, str.Length);
str.CopyTo(span);
FixHtml(span);
return span.ToString();
var fixedStr = span.ToString();
STArrayPool<char>.Shared.Return(chars);
return fixedStr;
}
public static void FixHtml(Span<char> chars)
public static void FixHtml(this Span<char> chars)
{
if (chars.Length == 0)
{
return;
}
ReadOnlySpan<char> invalid = stackalloc []{ '<', '>', '#' };
ReadOnlySpan<char> replacement = stackalloc []{ '(', ')', '-' };
ReadOnlySpan<char> invalid = ['<', '>', '#'];
ReadOnlySpan<char> replacement = ['(', ')', '-'];
chars.ReplaceAny(invalid, replacement);
}
public static PooledArraySpanFormattable FixHtmlFormattable(string str)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static PooledArraySpanFormattable FixHtmlFormattable(this string str) =>
((ReadOnlySpan<char>)str).FixHtmlFormattable();
public static PooledArraySpanFormattable FixHtmlFormattable(this ReadOnlySpan<char> str)
{
var chars = str.ToPooledArray();
var chars = STArrayPool<char>.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<T>();
return [];
}
var length = source.Count;
@ -1225,14 +1232,14 @@ public static class Utility
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Add<T>(ref List<T> list, T value)
{
list ??= new List<T>();
list ??= [];
list.Add(value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Add<T>(ref HashSet<T> set, T value)
{
set ??= new HashSet<T>();
set ??= [];
set.Add(value);
}
@ -1504,8 +1511,7 @@ public static class Utility
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNullOrWhiteSpace(this ReadOnlySpan<char> span) =>
span == default || span.IsEmpty || span.IsWhiteSpace();
public static bool IsNullOrWhiteSpace(this ReadOnlySpan<char> span) => span.IsEmpty || span.IsWhiteSpace();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool InTypeList<T>(this T obj, Type[] types) => obj.GetType().InTypeList(types);

View file

@ -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;

View file

@ -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.
}

View file

@ -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;

View file

@ -46,7 +46,7 @@ namespace Server.Engines.Help
10,
280,
20,
$"<basefont color=#A0A0FF><center>SPEECH LOG - {playerName} (<i>{Utility.FixHtmlFormattable(playerAccount)}</i>)</center></basefont>"
$"<basefont color=#A0A0FF><center>SPEECH LOG - {playerName} (<i>{playerAccount.FixHtmlFormattable()}</i>)</center></basefont>"
);
var lastPage = (log.Count - 1) / MaxEntriesPerPage;
@ -82,8 +82,8 @@ namespace Server.Engines.Help
builder.AppendFormat(
"<u>{0}</u> (<i>{1}</i>): {2}",
name,
Utility.FixHtml(account),
Utility.FixHtml(speech)
account.FixHtml(),
speech.FixHtml()
);
}

View file

@ -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)
{

View file

@ -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)
{

View file

@ -265,7 +265,7 @@ namespace Server.Guilds
return;
}
var title = Utility.FixHtml(text.Trim());
var title = text.Trim().FixHtml();
if (title.Length > 20)
{

View file

@ -677,7 +677,7 @@ namespace Server.Guilds
}
else
{
var name = Utility.FixHtml(text.Trim());
var name = text.Trim().FixHtml();
if (!CheckProfanity(name))
{

View file

@ -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<RunebookGump>();
from.SendGump(new RunebookGump(from, m_Book));

View file

@ -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.");
}

View file

@ -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)

View file

@ -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()}]");
}
}

View file

@ -234,7 +234,7 @@ public partial class Key : Item
return;
}
_key.Description = Utility.FixHtml(text);
_key.Description = text.FixHtml();
}
}

View file

@ -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;

View file

@ -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));
}

View file

@ -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)
{

View file

@ -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)