3 // namespace: System.Text.RegularExpressions
\r
4 // file: collections.cs
\r
6 // author: Dan Lewis (dlewis@gmx.co.uk)
\r
10 using System.Collections;
\r
12 namespace System.Text.RegularExpressions {
\r
13 public abstract class RegexCollectionBase : ICollection, IEnumerable {
\r
15 get { return list.Count; }
\r
18 public bool IsReadOnly {
\r
19 get { return true; } // FIXME
\r
22 public bool IsSynchronized {
\r
23 get { return false; } // FIXME
\r
26 public object SyncRoot {
\r
27 get { return list; } // FIXME
\r
30 public void CopyTo (Array array, int index) {
\r
31 foreach (Object o in list) {
\r
32 if (index > array.Length)
\r
35 array.SetValue (o, index ++);
\r
39 public IEnumerator GetEnumerator () {
\r
40 return new Enumerator (list);
\r
45 internal RegexCollectionBase () {
\r
46 list = new ArrayList ();
\r
49 internal void Add (Object o) {
\r
53 internal void Reverse () {
\r
57 // IEnumerator implementation
\r
59 private class Enumerator : IEnumerator {
\r
60 public Enumerator (IList list) {
\r
65 public object Current {
\r
67 if (ptr >= list.Count)
\r
68 throw new InvalidOperationException ();
\r
74 public bool MoveNext () {
\r
75 if (ptr > list.Count)
\r
76 throw new InvalidOperationException ();
\r
78 return ++ ptr < list.Count;
\r
81 public void Reset () {
\r
91 protected ArrayList list;
\r
95 public class CaptureCollection : RegexCollectionBase, ICollection, IEnumerable {
\r
96 public Capture this[int i] {
\r
97 get { return (Capture)list[i]; }
\r
100 internal CaptureCollection () {
\r
105 public class GroupCollection : RegexCollectionBase, ICollection, IEnumerable {
\r
106 public Group this[int i] {
\r
107 get { return (Group)list[i]; }
\r
110 public Group this[string groupName] {
\r
112 foreach (object o in list) {
\r
116 int index = ((Match) o).Regex.GroupNumberFromName (groupName);
\r
118 return this [index];
\r
125 internal GroupCollection () {
\r
130 public class MatchCollection : RegexCollectionBase, ICollection, IEnumerable {
\r
131 public virtual Match this[int i] {
\r
132 get { return (Match)list[i]; }
\r
135 internal MatchCollection () {
\r