2 // System.CharEnumerator.cs
4 // Author: Duncan Mak (duncan@ximian.com)
9 using System.Collections;
14 public sealed class CharEnumerator : IEnumerator, ICloneable
19 // Representation invariant:
20 // length == str.Length
21 // -1 <= index <= length
24 internal CharEnumerator (string s)
35 if (index == -1 || index == length)
36 throw new InvalidOperationException
37 ("The position is not valid.");
43 object IEnumerator.Current
46 if (index == -1 || index == length)
47 throw new InvalidOperationException
48 ("The position is not valid");
55 public object Clone ()
57 CharEnumerator x = new CharEnumerator (str);
62 public bool MoveNext ()
64 // Representation invariant holds: -1 <= index <= length
68 // Now: 0 <= index <= length+1;
70 // 0 <= index < length (OK) ||
71 // length <= index <= length+1 (Out of bounds)
73 if (index >= length) {
75 // Invariant restored:
78 // -1 <= index <= length