diff options
| author | dkanada <dkanada@users.noreply.github.com> | 2020-02-01 03:29:16 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-01 03:29:16 +0900 |
| commit | cd13f718fb52c507512615fad08e3c3670834163 (patch) | |
| tree | edea8b497082d3d9715c4de0fdc400e0a5db5425 /MediaBrowser.Model/Extensions/StringHelper.cs | |
| parent | b3811a9498fe06b68693f4a269de902cdd7eb2a2 (diff) | |
| parent | 6cd9c84ddf4940a5db1c3d84f1f61a89e5b4e168 (diff) | |
Merge pull request #2247 from Bond-009/stringhelper
Remove StringHelper functions
Diffstat (limited to 'MediaBrowser.Model/Extensions/StringHelper.cs')
| -rw-r--r-- | MediaBrowser.Model/Extensions/StringHelper.cs | 63 |
1 files changed, 22 insertions, 41 deletions
diff --git a/MediaBrowser.Model/Extensions/StringHelper.cs b/MediaBrowser.Model/Extensions/StringHelper.cs index 75ba12a17..f97a07096 100644 --- a/MediaBrowser.Model/Extensions/StringHelper.cs +++ b/MediaBrowser.Model/Extensions/StringHelper.cs @@ -1,57 +1,38 @@ -using System; -using System.Text; - namespace MediaBrowser.Model.Extensions { /// <summary> - /// Isolating these helpers allow this entire project to be easily converted to Java + /// Helper methods for manipulating strings. /// </summary> public static class StringHelper { /// <summary> - /// Equalses the ignore case. + /// Returns the string with the first character as uppercase. /// </summary> - /// <param name="str1">The STR1.</param> - /// <param name="str2">The STR2.</param> - /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> - public static bool EqualsIgnoreCase(string str1, string str2) + /// <param name="str">The input string.</param> + /// <returns>The string with the first character as uppercase.</returns> + public static string FirstToUpper(string str) { - return string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase); - } - - /// <summary> - /// Replaces the specified STR. - /// </summary> - /// <param name="str">The STR.</param> - /// <param name="oldValue">The old value.</param> - /// <param name="newValue">The new value.</param> - /// <param name="comparison">The comparison.</param> - /// <returns>System.String.</returns> - 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) + if (string.IsNullOrEmpty(str)) { - sb.Append(str.Substring(previousIndex, index - previousIndex)); - sb.Append(newValue); - index += oldValue.Length; - - previousIndex = index; - index = str.IndexOf(oldValue, index, comparison); + return string.Empty; } - sb.Append(str.Substring(previousIndex)); - - return sb.ToString(); - } + if (char.IsUpper(str[0])) + { + return str; + } - public static string FirstToUpper(this string str) - { - return string.IsNullOrEmpty(str) ? string.Empty : str.Substring(0, 1).ToUpperInvariant() + str.Substring(1); + return string.Create( + str.Length, + str, + (chars, buf) => + { + chars[0] = char.ToUpperInvariant(buf[0]); + for (int i = 1; i < chars.Length; i++) + { + chars[i] = buf[i]; + } + }); } } } |
