* CharEnumerator.cs: Implemented.
[mono.git] / mcs / class / corlib / System / CharEnumerator.cs
1 //
2 // System.CharEnumerator.cs
3 //
4 // Author: Duncan Mak  (duncan@ximian.com)
5 //
6 // (C) Ximian, Inc.
7 //
8
9 using System.Collections;
10
11 namespace System
12 {
13            [Serializable]
14            public sealed class CharEnumerator : IEnumerator, ICloneable
15            {
16                  private string str;
17                  private int idx;
18                          
19            // Constructor
20                  internal CharEnumerator (string s)
21                  {
22                             str = s;
23                             idx = -1;
24                  }
25                          
26                  // Property
27                  public char Current
28                  {
29                             get {
30                                   if (idx == -1)
31                                                 throw new InvalidOperationException ("The position is not valid.");
32                                                                                   
33                                   return str[idx];
34                             }
35                  }
36
37                  object IEnumerator.Current {
38                             get {
39                                           if (idx == -1)
40                                                         throw new InvalidOperationException ("The position is not valid");
41                                           return str [idx];
42                             }
43                  }
44                          
45                  // Methods
46                  public object Clone ()
47                  {
48                             CharEnumerator x = new CharEnumerator (str);
49                             x.idx = idx;
50                             return x;
51                  }
52                          
53                  public bool MoveNext ()
54                  {
55                             if (idx > str.Length) {
56                                           idx = -1;
57                                           return false;
58                             } else
59                                           return true;
60                  }
61                          
62                  public void Reset ()
63                  {
64                             idx = 0;
65                  }
66    }
67 }