aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Extensions/StringExtensions.cs
diff options
context:
space:
mode:
authorPika <15848969+ThatNerdyPikachu@users.noreply.github.com>2020-07-23 18:59:25 -0400
committerGitHub <noreply@github.com>2020-07-23 18:59:25 -0400
commit3b21abd879c278bdc7d2f02a62eba3a57cb55987 (patch)
treef045e94b60f1f8d6eb63bfda957209e110b1d82c /MediaBrowser.Common/Extensions/StringExtensions.cs
parent7aba10eff67151a9f6593e9d3d702f17029b994f (diff)
parent845ee21ddce8ed91d8c3c1463d0d7a06bb769635 (diff)
Merge branch 'master' into more-track-titles
Diffstat (limited to 'MediaBrowser.Common/Extensions/StringExtensions.cs')
-rw-r--r--MediaBrowser.Common/Extensions/StringExtensions.cs37
1 files changed, 37 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Extensions/StringExtensions.cs b/MediaBrowser.Common/Extensions/StringExtensions.cs
new file mode 100644
index 000000000..764301741
--- /dev/null
+++ b/MediaBrowser.Common/Extensions/StringExtensions.cs
@@ -0,0 +1,37 @@
+#nullable enable
+
+using System;
+
+namespace MediaBrowser.Common.Extensions
+{
+ /// <summary>
+ /// Extensions methods to simplify string operations.
+ /// </summary>
+ public static class StringExtensions
+ {
+ /// <summary>
+ /// Returns the part on the left of the <c>needle</c>.
+ /// </summary>
+ /// <param name="haystack">The string to seek.</param>
+ /// <param name="needle">The needle to find.</param>
+ /// <returns>The part left of the <paramref name="needle" />.</returns>
+ public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, char needle)
+ {
+ var pos = haystack.IndexOf(needle);
+ return pos == -1 ? haystack : haystack[..pos];
+ }
+
+ /// <summary>
+ /// Returns the part on the left of the <c>needle</c>.
+ /// </summary>
+ /// <param name="haystack">The string to seek.</param>
+ /// <param name="needle">The needle to find.</param>
+ /// <param name="stringComparison">One of the enumeration values that specifies the rules for the search.</param>
+ /// <returns>The part left of the <c>needle</c>.</returns>
+ public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, ReadOnlySpan<char> needle, StringComparison stringComparison = default)
+ {
+ var pos = haystack.IndexOf(needle, stringComparison);
+ return pos == -1 ? haystack : haystack[..pos];
+ }
+ }
+}