|
@@ -1,4 +1,4 @@
|
|
|
-/*
|
|
|
+/*
|
|
|
MIT License
|
|
|
|
|
|
Copyright (c) 2019 Gérald Barré
|
|
@@ -22,13 +22,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
SOFTWARE.
|
|
|
*/
|
|
|
|
|
|
-#pragma warning disable CS1591
|
|
|
-#pragma warning disable CA1034
|
|
|
+// TODO: remove when analyzer is fixed: https://github.com/dotnet/roslyn-analyzers/issues/5158
|
|
|
+#pragma warning disable CA1034 // Nested types should not be visible
|
|
|
+
|
|
|
using System;
|
|
|
using System.Diagnostics.Contracts;
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
-namespace MediaBrowser.Common.Extensions
|
|
|
+namespace Jellyfin.Extensions
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// Extension class for splitting lines without unnecessary allocations.
|
|
@@ -42,7 +43,7 @@ namespace MediaBrowser.Common.Extensions
|
|
|
/// <param name="separator">The separator to split on.</param>
|
|
|
/// <returns>The enumerator struct.</returns>
|
|
|
[Pure]
|
|
|
- public static SplitEnumerator SpanSplit(this string str, char separator) => new (str.AsSpan(), separator);
|
|
|
+ public static Enumerator SpanSplit(this string str, char separator) => new (str.AsSpan(), separator);
|
|
|
|
|
|
/// <summary>
|
|
|
/// Creates a new span split enumerator.
|
|
@@ -51,25 +52,44 @@ namespace MediaBrowser.Common.Extensions
|
|
|
/// <param name="separator">The separator to split on.</param>
|
|
|
/// <returns>The enumerator struct.</returns>
|
|
|
[Pure]
|
|
|
- public static SplitEnumerator Split(this ReadOnlySpan<char> str, char separator) => new (str, separator);
|
|
|
+ public static Enumerator Split(this ReadOnlySpan<char> str, char separator) => new (str, separator);
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Provides an enumerator for the substrings seperated by the separator.
|
|
|
+ /// </summary>
|
|
|
[StructLayout(LayoutKind.Auto)]
|
|
|
- public ref struct SplitEnumerator
|
|
|
+ public ref struct Enumerator
|
|
|
{
|
|
|
private readonly char _separator;
|
|
|
private ReadOnlySpan<char> _str;
|
|
|
|
|
|
- public SplitEnumerator(ReadOnlySpan<char> str, char separator)
|
|
|
+ /// <summary>
|
|
|
+ /// Initializes a new instance of the <see cref="Enumerator"/> struct.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="str">The span to split.</param>
|
|
|
+ /// <param name="separator">The separator to split on.</param>
|
|
|
+ public Enumerator(ReadOnlySpan<char> str, char separator)
|
|
|
{
|
|
|
_str = str;
|
|
|
_separator = separator;
|
|
|
Current = default;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Gets a reference to the item at the current position of the enumerator.
|
|
|
+ /// </summary>
|
|
|
public ReadOnlySpan<char> Current { get; private set; }
|
|
|
|
|
|
- public readonly SplitEnumerator GetEnumerator() => this;
|
|
|
+ /// <summary>
|
|
|
+ /// Returns <c>this</c>.
|
|
|
+ /// </summary>
|
|
|
+ /// <returns><c>this</c>.</returns>
|
|
|
+ public readonly Enumerator GetEnumerator() => this;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Advances the enumerator to the next item.
|
|
|
+ /// </summary>
|
|
|
+ /// <returns><c>true</c> if there is a next element; otherwise <c>false</c>.</returns>
|
|
|
public bool MoveNext()
|
|
|
{
|
|
|
if (_str.Length == 0)
|