Skip to content

Commit dd98d20

Browse files
committed
Merge
1 parent 4fe1abe commit dd98d20

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Split.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,49 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
using System.Buffers;
44
using System.Diagnostics;
5+
using System.Diagnostics.CodeAnalysis;
56

67
namespace System
78
{
89
public static partial class MemoryExtensions
910
{
11+
/// <summary>
12+
/// Returns a type that allows for enumeration of each element within a split span
13+
/// using the provided separator character.
14+
/// </summary>
15+
/// <param name="source">The source span to be enumerated.</param>
16+
/// <param name="separator">The separator character to be used to split the provided span.</param>
17+
/// <returns>Returns a <see cref="System.MemoryExtensions.SpanSplitEnumerator{T}"/>.</returns>
1018
public static SpanSplitEnumerator<T> Split<T>(this ReadOnlySpan<T> source, T separator)
1119
where T : IEquatable<T> => new SpanSplitEnumerator<T>(source, separator);
20+
21+
/// <summary>
22+
/// Returns a type that allows for enumeration of each element within a split span
23+
/// using the provided separator span.
24+
/// </summary>
25+
/// <param name="source">The source span to be enumerated.</param>
26+
/// <param name="separator">The separator span to be used to split the provided span.</param>
27+
/// <returns>Returns a <see cref="System.MemoryExtensions.SpanSplitEnumerator{T}"/>.</returns>
1228
public static SpanSplitEnumerator<T> Split<T>(this ReadOnlySpan<T> source, ReadOnlySpan<T> separator)
1329
where T : IEquatable<T> => new SpanSplitEnumerator<T>(source, separator, treatAsSingleSeparator: true);
14-
public static SpanSplitEnumerator<T> SplitAny<T>(this ReadOnlySpan<T> source, [System.Diagnostics.CodeAnalysis.UnscopedRef] params ReadOnlySpan<T> separators)
30+
31+
/// <summary>
32+
/// Returns a type that allows for enumeration of each element within a split span
33+
/// using any of the provided elements.
34+
/// </summary>
35+
/// <param name="source">The source span to be enumerated.</param>
36+
/// <param name="separators">The separators to be used to split the provided span.</param>
37+
/// <returns>Returns a <see cref="System.MemoryExtensions.SpanSplitEnumerator{T}"/>.</returns>
38+
public static SpanSplitEnumerator<T> SplitAny<T>(this ReadOnlySpan<T> source, [UnscopedRef] params ReadOnlySpan<T> separators)
1539
where T : IEquatable<T> => new SpanSplitEnumerator<T>(source, separators, treatAsSingleSeparator: false);
40+
41+
/// <summary>
42+
/// Returns a type that allows for enumeration of each element within a split span
43+
/// using the provided <see cref="System.MemoryExtensions.SpanSplitEnumerator{T}"/>.
44+
/// </summary>
45+
/// <param name="source">The source span to be enumerated.</param>
46+
/// <param name="separators">The <see cref="System.MemoryExtensions.SpanSplitEnumerator{T}"/> to be used to split the provided span.</param>
47+
/// <returns>Returns a <see cref="System.MemoryExtensions.SpanSplitEnumerator{T}"/>.</returns>
1648
public static SpanSplitEnumerator<T> SplitAny<T>(this ReadOnlySpan<T> source, SearchValues<T> separators)
1749
where T : IEquatable<T> => new SpanSplitEnumerator<T>(source, separators);
1850

@@ -26,6 +58,10 @@ private enum SpanSplitEnumeratorMode
2658
SearchValues
2759
}
2860

61+
/// <summary>
62+
/// <see cref="System.MemoryExtensions.SpanSplitEnumerator{T}"/> allows for enumeration of each element within a <see cref="System.ReadOnlySpan{T}"/>
63+
/// that has been split using a provided separator.
64+
/// </summary>
2965
public ref struct SpanSplitEnumerator<T> where T : IEquatable<T>
3066
{
3167
private readonly ReadOnlySpan<T> _span;
@@ -41,8 +77,16 @@ private enum SpanSplitEnumeratorMode
4177
private int _endCurrent = 0;
4278
private int _startNext = 0;
4379

80+
/// <summary>
81+
/// Returns an enumerator that allows for iteration over the split span.
82+
/// </summary>
83+
/// <returns>Returns a <see cref="System.MemoryExtensions.SpanSplitEnumerator{T}"/> that can be used to iterate over the split span.</returns>
4484
public SpanSplitEnumerator<T> GetEnumerator() => this;
4585

86+
/// <summary>
87+
/// Returns the current element of the enumeration.
88+
/// </summary>
89+
/// <returns>Returns a <see cref="System.Range"/> instance that indicates the bounds of the current element withing the source span.</returns>
4690
public Range Current => new Range(_startCurrent, _endCurrent);
4791

4892
internal SpanSplitEnumerator(ReadOnlySpan<T> span, SearchValues<T> searchValues)
@@ -71,6 +115,10 @@ internal SpanSplitEnumerator(ReadOnlySpan<T> span, T separator)
71115
_splitMode = SpanSplitEnumeratorMode.SingleToken;
72116
}
73117

118+
/// <summary>
119+
/// Advances the enumerator to the next element of the enumeration.
120+
/// </summary>
121+
/// <returns><see langword="true"/> if the enumerator was successfully advanced to the next element; <see langword="false"/> if the enumerator has passed the end of the enumeration.</returns>
74122
public bool MoveNext()
75123
{
76124
if (_splitMode is SpanSplitEnumeratorMode.None || _startNext > _span.Length)

0 commit comments

Comments
 (0)