MatchCollection.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // System.Text.RegularExpressions.MatchCollection
  3. //
  4. // Authors:
  5. // Dan Lewis ([email protected])
  6. // Dick Porter ([email protected])
  7. //
  8. // (C) 2002 Dan Lewis
  9. // (C) 2004 Novell, Inc.
  10. //
  11. using System;
  12. using System.Collections;
  13. namespace System.Text.RegularExpressions
  14. {
  15. [Serializable]
  16. public class MatchCollection: ICollection, IEnumerable
  17. {
  18. private ArrayList list;
  19. /* No public constructor */
  20. internal MatchCollection () {
  21. list = new ArrayList ();
  22. }
  23. public virtual int Count {
  24. get {
  25. return(list.Count);
  26. }
  27. }
  28. public bool IsReadOnly {
  29. get {
  30. return(true);
  31. }
  32. }
  33. public virtual bool IsSynchronized {
  34. get {
  35. return(false);
  36. }
  37. }
  38. public Match this[int i] {
  39. get {
  40. if (i < 0 ||
  41. i > Count) {
  42. throw new ArgumentOutOfRangeException ("Index is out of range");
  43. }
  44. return((Match)list[i]);
  45. }
  46. }
  47. public virtual object SyncRoot {
  48. get {
  49. return(list);
  50. }
  51. }
  52. public virtual void CopyTo (Array array, int index) {
  53. foreach (object o in list) {
  54. if (index > array.Length) {
  55. break;
  56. }
  57. array.SetValue (o, index++);
  58. }
  59. }
  60. public virtual IEnumerator GetEnumerator () {
  61. return(new Enumerator (list));
  62. }
  63. internal void Add (object o) {
  64. list.Add (o);
  65. }
  66. internal void Reverse () {
  67. list.Reverse ();
  68. }
  69. private class Enumerator: IEnumerator {
  70. private IList list;
  71. private int ptr;
  72. public Enumerator (IList list) {
  73. this.list = list;
  74. Reset ();
  75. }
  76. public object Current {
  77. get {
  78. if (ptr >= list.Count) {
  79. throw new InvalidOperationException ();
  80. }
  81. return(list[ptr]);
  82. }
  83. }
  84. public bool MoveNext () {
  85. if (ptr > list.Count) {
  86. throw new InvalidOperationException ();
  87. }
  88. return(++ptr < list.Count);
  89. }
  90. public void Reset () {
  91. ptr = -1;
  92. }
  93. }
  94. }
  95. }