From a86b71899ec52c44ddc6c3018e8cc5e9d7ff4d62 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Thu, 27 Dec 2018 18:27:57 -0500 Subject: Add GPL modules --- MediaBrowser.Model/Extensions/StringHelper.cs | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 MediaBrowser.Model/Extensions/StringHelper.cs (limited to 'MediaBrowser.Model/Extensions/StringHelper.cs') diff --git a/MediaBrowser.Model/Extensions/StringHelper.cs b/MediaBrowser.Model/Extensions/StringHelper.cs new file mode 100644 index 000000000..fa79d09db --- /dev/null +++ b/MediaBrowser.Model/Extensions/StringHelper.cs @@ -0,0 +1,57 @@ +using System; +using System.Text; + +namespace MediaBrowser.Model.Extensions +{ + /// + /// Isolating these helpers allow this entire project to be easily converted to Java + /// + public static class StringHelper + { + /// + /// Equalses the ignore case. + /// + /// The STR1. + /// The STR2. + /// true if XXXX, false otherwise. + public static bool EqualsIgnoreCase(string str1, string str2) + { + return string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase); + } + + /// + /// Replaces the specified STR. + /// + /// The STR. + /// The old value. + /// The new value. + /// The comparison. + /// System.String. + public static string Replace(this string str, string oldValue, string newValue, StringComparison comparison) + { + var sb = new StringBuilder(); + + var previousIndex = 0; + var index = str.IndexOf(oldValue, comparison); + + while (index != -1) + { + sb.Append(str.Substring(previousIndex, index - previousIndex)); + sb.Append(newValue); + index += oldValue.Length; + + previousIndex = index; + index = str.IndexOf(oldValue, index, comparison); + } + + sb.Append(str.Substring(previousIndex)); + + return sb.ToString(); + } + + public static string FirstToUpper(this string str) + { + return string.IsNullOrEmpty(str) ? "" : str.Substring(0, 1).ToUpper() + str.Substring(1); + } + } +} -- cgit v1.2.3