Welcome to mirror list, hosted at ThFree Co, Russian Federation.

collections.cs « System.Text.RegularExpressions « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a56d27effa2d961a1cba285e557f2a513c65bc7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// assembly:	System
// namespace:	System.Text.RegularExpressions
// file:	collections.cs
//
// author:	Dan Lewis (dlewis@gmx.co.uk)
// 		(c) 2002

using System;
using System.Collections;

namespace System.Text.RegularExpressions {
	public abstract class RegexCollectionBase : ICollection, IEnumerable {
		public int Count {
			get { return list.Count; }
		}

		public bool IsReadOnly {
			get { return true; }	// FIXME
		}

		public bool IsSynchronized {
			get { return false; }	// FIXME
		}

		public object SyncRoot {
			get { return list; }	// FIXME
		}

		public void CopyTo (Array array, int index) {
			foreach (Object o in list) {
				if (index > array.Length)
					break;
				
				array.SetValue (o, index ++);
			}
		}

		public IEnumerator GetEnumerator () {
			return new Enumerator (list);
		}

		// internal methods

		internal RegexCollectionBase () {
			list = new ArrayList ();
		}

		internal void Add (Object o) {
			list.Add (o);
		}

		internal void Reverse () {
			list.Reverse ();
		}

		// IEnumerator implementation

		private class Enumerator : IEnumerator {
			public Enumerator (IList list) {
				this.list = list;
				Reset ();
			}

			public object Current {
				get {
					if (ptr >= list.Count)
						throw new InvalidOperationException ();

					return list[ptr];
				}
			}

			public bool MoveNext () {
				if (ptr > list.Count)
					throw new InvalidOperationException ();
				
				return ++ ptr < list.Count;
			}

			public void Reset () {
				ptr = -1;
			}

			private IList list;
			private int ptr;
		}

		// protected fields

		protected ArrayList list;
	}

	[Serializable]
	public class CaptureCollection : RegexCollectionBase, ICollection, IEnumerable {
		public Capture this[int i] {
			get { return (Capture)list[i]; }
		}

		internal CaptureCollection () {
		}
	}

	[Serializable]
	public class GroupCollection : RegexCollectionBase, ICollection, IEnumerable {
		public Group this[int i] {
			get { return (Group)list[i]; }
		}
		
		internal GroupCollection () {
		}
	}

	[Serializable]
	public class MatchCollection : RegexCollectionBase, ICollection, IEnumerable {
		public virtual Match this[int i] {
			get { return (Match)list[i]; }
		}

		internal MatchCollection () {
		}
	}
}