using System;
using System.Linq;
namespace Jellyfin.Api.Helpers
{
///
/// Request Extensions.
///
public static class RequestHelpers
{
///
/// Splits a string at a separating character into an array of substrings.
///
/// The string to split.
/// The char that separates the substrings.
/// Option to remove empty substrings from the array.
/// An array of the substrings.
internal static string[] Split(string value, char separator, bool removeEmpty)
{
if (string.IsNullOrWhiteSpace(value))
{
return Array.Empty();
}
return removeEmpty
? value.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries)
: value.Split(separator);
}
///
/// Splits a comma delimited string and parses Guids.
///
/// Input value.
/// Parsed Guids.
public static Guid[] GetGuids(string value)
{
if (value == null)
{
return Array.Empty();
}
return value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(i => new Guid(i))
.ToArray();
}
}
}