From dfd74933c74bb036d162646de08826643411d136 Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Wed, 10 Jan 2024 01:20:43 +0300 Subject: [PATCH] Fixed string.Incognify not working correctly with short strings --- .../Core/Extensions/StringExtensions.cs | 18 ++++++++++++------ CustomizePlus/CustomizePlus.csproj | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CustomizePlus/Core/Extensions/StringExtensions.cs b/CustomizePlus/Core/Extensions/StringExtensions.cs index 312e980..aefb33b 100644 --- a/CustomizePlus/Core/Extensions/StringExtensions.cs +++ b/CustomizePlus/Core/Extensions/StringExtensions.cs @@ -1,4 +1,5 @@ using Dalamud.Utility; +using System; namespace CustomizePlus.Core.Extensions; @@ -15,17 +16,22 @@ internal static class StringExtensions #if !INCOGNIFY_STRINGS return str; #endif - if (str.Contains(" ")) { var split = str.Split(' '); - if (split.Length > 2) - return $"{str[..5]}..."; - - return $"{split[0][0]}.{split[1][0]}"; + if (split.Length == 2) + return $"{split[0][0]}.{split[1][0]}"; } - return $"{str[..5]}..."; + return str.GetCutString(); + } + + private static string GetCutString(this string str, int maxLength = 5) + { + if(str.Length > maxLength) + return $"{str[..maxLength]}..."; + else + return str[0..Math.Min(str.Length, maxLength)]; } } diff --git a/CustomizePlus/CustomizePlus.csproj b/CustomizePlus/CustomizePlus.csproj index 255756c..bf35d6f 100644 --- a/CustomizePlus/CustomizePlus.csproj +++ b/CustomizePlus/CustomizePlus.csproj @@ -4,7 +4,7 @@ - 2.0.0.1 + 2.0.0.2 Customize+ https://github.com/Aether-Tools/CustomizePlus