#nullable enable
using System;
namespace MediaBrowser.Common.Extensions
{
///
/// Extensions methods to simplify string operations.
///
public static class StringExtensions
{
///
/// Returns the part left of the needle.
///
/// The string to seek.
/// The needle to find.
/// The part left of the needle.
public static ReadOnlySpan LeftPart(this ReadOnlySpan str, char needle)
{
var pos = str.IndexOf(needle);
return pos == -1 ? str : str[..pos];
}
///
/// Returns the part 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 str, ReadOnlySpan needle, StringComparison stringComparison = default)
{
var pos = str.IndexOf(needle, stringComparison);
return pos == -1 ? str : str[..pos];
}
}
}