diff options
| author | Bond-009 <bond.009@outlook.com> | 2021-09-25 22:24:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-25 22:24:57 +0200 |
| commit | 8858d8e59789ee3ad7b55077900d80437ef982b5 (patch) | |
| tree | b53f72bc270c09b33ff6d5eb4e57cd902ccad4a8 /src/Jellyfin.Extensions/StringExtensions.cs | |
| parent | 19b8bcaec43835c698a35975a748c2129c1413aa (diff) | |
| parent | 82cb6851786d4fb24952d77d869f9e9c005a960a (diff) | |
Merge branch 'master' into theorydata
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)..]; + } } } |
