Fix ReplacementAccentSystem out of range exception (#16786)

This commit is contained in:
themias
2023-05-24 15:03:43 -04:00
committed by GitHub
parent f1deacadbc
commit 1781a9da06

View File

@@ -53,8 +53,10 @@ namespace Content.Server.Speech.EntitySystems
// this is kind of slow but its not that bad
// essentially: go over all matches, try to match capitalization where possible, then replace
// rather than using regex.replace
foreach (Match match in Regex.Matches(message, $@"(?<!\w){f}(?!\w)", RegexOptions.IgnoreCase))
for (int i = Regex.Count(message, $@"(?<!\w){f}(?!\w)", RegexOptions.IgnoreCase); i > 0; i--)
{
// fetch the match again as the character indices may have changed
Match match = Regex.Match(message, $@"(?<!\w){f}(?!\w)", RegexOptions.IgnoreCase);
var replacement = r;
// Intelligently replace capitalization