Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Update regular expressions collections to implement IReadOnlyList<T> #277

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// contained in a compiled Regex.

using System.Collections;
using System.Collections.Generic;

namespace System.Text.RegularExpressions
{
Expand All @@ -17,7 +18,7 @@ namespace System.Text.RegularExpressions
/// Represents a sequence of capture substrings. The object is used
/// to return the set of captures done by a single capturing group.
/// </summary>
public class CaptureCollection : ICollection
public class CaptureCollection : ICollection, IReadOnlyList<Capture>
{
internal Group _group;
internal int _capcount;
Expand Down Expand Up @@ -93,6 +94,11 @@ public IEnumerator GetEnumerator()
return new CaptureEnumerator(this);
}

IEnumerator<Capture> IEnumerable<Capture>.GetEnumerator()
{
return new CaptureEnumerator(this);
}

/*
* Nonpublic code to return set of captures for the group
*/
Expand Down Expand Up @@ -124,7 +130,7 @@ internal Capture GetCapture(int i)
* Should it be public?
*/

internal class CaptureEnumerator : IEnumerator
internal class CaptureEnumerator : IEnumerator<Capture>
{
internal CaptureCollection _rcc;
internal int _curindex;
Expand Down Expand Up @@ -161,6 +167,11 @@ public Object Current
get { return Capture; }
}

Capture IEnumerator<Capture>.Current
{
get { return Capture; }
}

/*
* Returns the current capture
*/
Expand All @@ -182,5 +193,9 @@ public void Reset()
{
_curindex = -1;
}

void IDisposable.Dispose()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace System.Text.RegularExpressions
/// Represents a sequence of capture substrings. The object is used
/// to return the set of captures done by a single capturing group.
/// </summary>
public class GroupCollection : ICollection
public class GroupCollection : ICollection, IReadOnlyList<Group>
{
internal Match _match;
internal Dictionary<Int32, Int32> _captureMap;
Expand Down Expand Up @@ -148,14 +148,19 @@ public IEnumerator GetEnumerator()
{
return new GroupEnumerator(this);
}

IEnumerator<Group> IEnumerable<Group>.GetEnumerator()
{
return new GroupEnumerator(this);
}
}


/*
* This non-public enumerator lists all the captures
* Should it be public?
*/
internal class GroupEnumerator : IEnumerator
internal class GroupEnumerator : IEnumerator<Group>
{
internal GroupCollection _rgc;
internal int _curindex;
Expand Down Expand Up @@ -192,6 +197,11 @@ public Object Current
get { return Capture; }
}

Group IEnumerator<Group>.Current
{
get { return (Group)Capture; }
}

/*
* Returns the current capture
*/
Expand All @@ -213,5 +223,9 @@ public void Reset()
{
_curindex = -1;
}

void IDisposable.Dispose()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace System.Text.RegularExpressions
/// Represents the set of names appearing as capturing group
/// names in a regular expression.
/// </summary>
public class MatchCollection : ICollection
public class MatchCollection : ICollection, IReadOnlyList<Match>
{
internal Regex _regex;
internal List<Match> _matches;
Expand Down Expand Up @@ -159,13 +159,18 @@ public IEnumerator GetEnumerator()
{
return new MatchEnumerator(this);
}

IEnumerator<Match> IEnumerable<Match>.GetEnumerator()
{
return new MatchEnumerator(this);
}
}

/*
* This non-public enumerator lists all the group matches.
* Should it be public?
*/
internal class MatchEnumerator : IEnumerator
internal class MatchEnumerator : IEnumerator<Match>
{
internal MatchCollection _matchcoll;
internal Match _match = null;
Expand Down Expand Up @@ -213,6 +218,14 @@ public Object Current
}
}

Match IEnumerator<Match>.Current
{
get
{
return (Match)Current;
}
}

/*
* Position before the first item
*/
Expand All @@ -222,5 +235,9 @@ public void Reset()
_done = false;
_match = null;
}

void IDisposable.Dispose()
{
}
}
}