diff options
| author | Cody Robibero <cody@robibe.ro> | 2021-10-08 07:49:40 -0600 |
|---|---|---|
| committer | Cody Robibero <cody@robibe.ro> | 2021-10-08 07:49:40 -0600 |
| commit | 3bbd98cc3fb4e69b5d5471ab7cbdcc22d59a8eb9 (patch) | |
| tree | d6a0aeb4896ec9ab4305916f0380606483180786 /src/Jellyfin.Extensions/StringExtensions.cs | |
| parent | 7a7fe3e681eca87cde631336c9af565fd6dfe0d7 (diff) | |
| parent | a01f9775fffaacfd0fc03b24bff366b4701fe45e (diff) | |
Merge remote-tracking branch 'upstream/master' into schedules-direct
Diffstat (limited to 'src/Jellyfin.Extensions/StringExtensions.cs')
| -rw-r--r-- | src/Jellyfin.Extensions/StringExtensions.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Jellyfin.Extensions/StringExtensions.cs b/src/Jellyfin.Extensions/StringExtensions.cs index acc695ed2..3a7707253 100644 --- a/src/Jellyfin.Extensions/StringExtensions.cs +++ b/src/Jellyfin.Extensions/StringExtensions.cs @@ -27,5 +27,39 @@ namespace Jellyfin.Extensions return count; } + + /// <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 right 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 right of the <paramref name="needle" />.</returns> + public static ReadOnlySpan<char> RightPart(this ReadOnlySpan<char> haystack, char needle) + { + var pos = haystack.LastIndexOf(needle); + if (pos == -1) + { + return haystack; + } + + if (pos == haystack.Length - 1) + { + return ReadOnlySpan<char>.Empty; + } + + return haystack[(pos + 1)..]; + } } } |
