RequestHelpers.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Linq;
  3. namespace Jellyfin.Api.Helpers
  4. {
  5. /// <summary>
  6. /// Request Extensions.
  7. /// </summary>
  8. public static class RequestHelpers
  9. {
  10. /// <summary>
  11. /// Splits a string at a separating character into an array of substrings.
  12. /// </summary>
  13. /// <param name="value">The string to split.</param>
  14. /// <param name="separator">The char that separates the substrings.</param>
  15. /// <param name="removeEmpty">Option to remove empty substrings from the array.</param>
  16. /// <returns>An array of the substrings.</returns>
  17. internal static string[] Split(string value, char separator, bool removeEmpty)
  18. {
  19. if (string.IsNullOrWhiteSpace(value))
  20. {
  21. return Array.Empty<string>();
  22. }
  23. return removeEmpty
  24. ? value.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries)
  25. : value.Split(separator);
  26. }
  27. /// <summary>
  28. /// Splits a comma delimited string and parses Guids.
  29. /// </summary>
  30. /// <param name="value">Input value.</param>
  31. /// <returns>Parsed Guids.</returns>
  32. public static Guid[] GetGuids(string value)
  33. {
  34. if (value == null)
  35. {
  36. return Array.Empty<Guid>();
  37. }
  38. return value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
  39. .Select(i => new Guid(i))
  40. .ToArray();
  41. }
  42. }
  43. }