#nullable enable
using System;
namespace MediaBrowser.Common.Extensions
{
///
/// Extensions methods to simplify string operations.
///
public static class StringExtensions
{
///
/// Returns the part on the left of the needle.
///
/// The string to seek.
/// The needle to find.
/// The part left of the .
public static ReadOnlySpan LeftPart(this ReadOnlySpan haystack, char needle)
{
var pos = haystack.IndexOf(needle);
return pos == -1 ? haystack : haystack[..pos];
}
///
/// Returns the part on the left of the needle.
///
/// The string to seek.
/// The needle to find.
/// One of the enumeration values that specifies the rules for the search.
/// The part left of the needle.
public static ReadOnlySpan LeftPart(this ReadOnlySpan haystack, ReadOnlySpan needle, StringComparison stringComparison = default)
{
var pos = haystack.IndexOf(needle, stringComparison);
return pos == -1 ? haystack : haystack[..pos];
}
}
}