Huge indentation fix. Don't worry, I tested so no typos were introduced. ;-)
[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                 private int len;
19                 
20                 // Constructor
21                 internal CharEnumerator (string s)
22                  {
23                          str = s;
24                          idx = -1;
25                          len = s.Length;
26                  }
27                 
28                 // Property
29                 public char Current
30                 {
31                         get {
32                                 if (idx == -1)
33                                         throw new InvalidOperationException ("The position is not valid.");
34                                 
35                                 return str[idx];
36                         }
37                 }
38                 
39                 object IEnumerator.Current {
40                         get {
41                                 if (idx == -1)
42                                         throw new InvalidOperationException ("The position is not valid");
43                                 return str [idx];
44                         }
45                 }
46                 
47                 // Methods
48                 public object Clone ()
49                 {
50                         CharEnumerator x = new CharEnumerator (str);
51                         x.idx = idx;
52                         return x;
53                 }
54                 
55                 public bool MoveNext ()
56                 {
57                         if (len < 0)
58                                 return false;
59                         
60                         idx++;
61                         
62                         if (idx > len) {
63                                 idx = -2;
64                                 return false;
65                         }
66                         
67                         return true;
68                 }
69                 
70                 public void Reset ()
71                 {
72                         idx = -1;
73                 }
74         }
75 }