From ddeb3151c037e3ca81a81c40868bbcd597a5c07e Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 24 Jan 2024 21:46:08 +1100 Subject: [PATCH] remove StringReplace (#4569) --- .../Utils/StringExtensions.cs | 47 ------------------- .../CoreTests/StringExtensionTests.cs | 16 ------- 2 files changed, 63 deletions(-) diff --git a/src/client/Microsoft.Identity.Client/Utils/StringExtensions.cs b/src/client/Microsoft.Identity.Client/Utils/StringExtensions.cs index 34767c1000..fab8cb5c55 100644 --- a/src/client/Microsoft.Identity.Client/Utils/StringExtensions.cs +++ b/src/client/Microsoft.Identity.Client/Utils/StringExtensions.cs @@ -26,53 +26,6 @@ public static string NullIfWhiteSpace(this string s) { return string.IsNullOrWhiteSpace(s) ? null : s; } - - - /// - /// Culture aware String.Replace - /// - public static string Replace(this string src, string oldValue, string newValue, StringComparison comparison) - { - if (string.IsNullOrWhiteSpace(src)) - { - return src; - } - - if (string.IsNullOrWhiteSpace(oldValue)) - { - throw new ArgumentException("oldValue cannot be empty"); - } - - // skip the loop entirely if oldValue and newValue are the same - if (string.Compare(oldValue, newValue, comparison) == 0) - { - return src; - } - - if (oldValue.Length > src.Length) - { - return src; - } - - var sb = new StringBuilder(); - - int previousIndex = 0; - int index = src.IndexOf(oldValue, comparison); - - while (index != -1) - { - sb.Append(src.Substring(previousIndex, index - previousIndex)); - sb.Append(newValue); - index += oldValue.Length; - - previousIndex = index; - index = src.IndexOf(oldValue, index, comparison); - } - - sb.Append(src.Substring(previousIndex)); - - return sb.ToString(); - } #if NETSTANDARD2_0 || NETFRAMEWORK || WINDOWS_APP /// diff --git a/tests/Microsoft.Identity.Test.Unit/CoreTests/StringExtensionTests.cs b/tests/Microsoft.Identity.Test.Unit/CoreTests/StringExtensionTests.cs index 8cc572219d..f4badae3bb 100644 --- a/tests/Microsoft.Identity.Test.Unit/CoreTests/StringExtensionTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/CoreTests/StringExtensionTests.cs @@ -11,22 +11,6 @@ namespace Microsoft.Identity.Test.Unit.CoreTests [TestClass] public class StringExtensionTests { - [TestMethod] - public void StringReplace() - { - Assert.AreEqual("hi common !", "hi {tenant} !".Replace("{tenant}", "common", StringComparison.OrdinalIgnoreCase)); - Assert.AreEqual("hi commoncommon !", "hi {tenant}{tenant} !".Replace("{tenant}", "common", StringComparison.OrdinalIgnoreCase)); - Assert.AreEqual("hi common--common !", "hi {tenant}--{tenant} !".Replace("{tenant}", "common", StringComparison.OrdinalIgnoreCase)); - Assert.AreEqual("hi common !", "hi {tenaNt} !".Replace("{tEnant}", "common", StringComparison.OrdinalIgnoreCase)); - - Assert.AreEqual("hi common !", "hi {tenant_id} !".Replace("{tenant_ID}", "common", StringComparison.OrdinalIgnoreCase)); - Assert.AreEqual("hi {tenant_id} !", "hi {tenant_id} !".Replace("nothing", "common", StringComparison.OrdinalIgnoreCase)); - - Assert.AreEqual("", "".Replace("nothing", "common", StringComparison.OrdinalIgnoreCase)); - AssertException.Throws(() => - "hi {tenant} !".Replace("", "common", StringComparison.OrdinalIgnoreCase)); - } - [TestMethod] public void NullIfEmpty() {