Autocapitalize the word I in IC chat (#18633)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Content.Server.Administration.Logs;
|
using Content.Server.Administration.Logs;
|
||||||
@@ -199,8 +200,11 @@ public sealed partial class ChatSystem : SharedChatSystem
|
|||||||
|
|
||||||
bool shouldCapitalize = (desiredType != InGameICChatType.Emote);
|
bool shouldCapitalize = (desiredType != InGameICChatType.Emote);
|
||||||
bool shouldPunctuate = _configurationManager.GetCVar(CCVars.ChatPunctuation);
|
bool shouldPunctuate = _configurationManager.GetCVar(CCVars.ChatPunctuation);
|
||||||
|
// Capitalizing the word I only happens in English, so we check language here
|
||||||
|
bool shouldCapitalizeTheWordI = (!CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Parent.Name == "en")
|
||||||
|
|| (CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Name == "en");
|
||||||
|
|
||||||
message = SanitizeInGameICMessage(source, message, out var emoteStr, shouldCapitalize, shouldPunctuate);
|
message = SanitizeInGameICMessage(source, message, out var emoteStr, shouldCapitalize, shouldPunctuate, shouldCapitalizeTheWordI);
|
||||||
|
|
||||||
// Was there an emote in the message? If so, send it.
|
// Was there an emote in the message? If so, send it.
|
||||||
if (player != null && emoteStr != message && emoteStr != null)
|
if (player != null && emoteStr != message && emoteStr != null)
|
||||||
@@ -677,11 +681,13 @@ public sealed partial class ChatSystem : SharedChatSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once InconsistentNaming
|
// ReSharper disable once InconsistentNaming
|
||||||
private string SanitizeInGameICMessage(EntityUid source, string message, out string? emoteStr, bool capitalize = true, bool punctuate = false)
|
private string SanitizeInGameICMessage(EntityUid source, string message, out string? emoteStr, bool capitalize = true, bool punctuate = false, bool capitalizeTheWordI = true)
|
||||||
{
|
{
|
||||||
var newMessage = message.Trim();
|
var newMessage = message.Trim();
|
||||||
if (capitalize)
|
if (capitalize)
|
||||||
newMessage = SanitizeMessageCapital(newMessage);
|
newMessage = SanitizeMessageCapital(newMessage);
|
||||||
|
if (capitalizeTheWordI)
|
||||||
|
newMessage = SanitizeMessageCapitalizeTheWordI(newMessage, "i");
|
||||||
if (punctuate)
|
if (punctuate)
|
||||||
newMessage = SanitizeMessagePeriod(newMessage);
|
newMessage = SanitizeMessagePeriod(newMessage);
|
||||||
|
|
||||||
|
|||||||
@@ -162,4 +162,33 @@ public abstract class SharedChatSystem : EntitySystem
|
|||||||
message = char.ToUpper(message[0]) + message.Remove(0, 1);
|
message = char.ToUpper(message[0]) + message.Remove(0, 1);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string SanitizeMessageCapitalizeTheWordI(string message, string theWordI = "i")
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(message))
|
||||||
|
return message;
|
||||||
|
|
||||||
|
for
|
||||||
|
(
|
||||||
|
var index = message.IndexOf(theWordI);
|
||||||
|
index != -1;
|
||||||
|
index = message.IndexOf(theWordI, index + 1)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Stops the code If It's tryIng to capItalIze the letter I In the mIddle of words
|
||||||
|
// Repeating the code twice is the simplest option
|
||||||
|
if (index + 1 < message.Length && char.IsLetter(message[index + 1]))
|
||||||
|
continue;
|
||||||
|
if (index - 1 >= 0 && char.IsLetter(message[index - 1]))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var beforeTarget = message.Substring(0, index);
|
||||||
|
var target = message.Substring(index, theWordI.Length);
|
||||||
|
var afterTarget = message.Substring(index + theWordI.Length);
|
||||||
|
|
||||||
|
message = beforeTarget + target.ToUpper() + afterTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user