2004-04-30 Dick Porter <dick@ximian.com>
[mono.git] / mcs / class / corlib / System.Globalization / TextElementEnumerator.cs
1 //
2 // System.Globalization.TextElementEnumerator.cs
3 //
4 // Author:
5 //      Dick Porter (dick@ximian.com)
6 //
7 // (C) 2002 Ximian, Inc.
8 // (C) 2004 Novell, Inc.
9 //
10
11 using System.Collections;
12
13 namespace System.Globalization {
14
15         [Serializable]
16         public class TextElementEnumerator: IEnumerator {
17                 private int index;
18                 private int elementindex;
19                 private int startpos;
20                 private string str;
21                 private string element;
22                 
23                 /* Hide the .ctor() */
24                 internal TextElementEnumerator(string str, int startpos) {
25                         this.index = -1;
26                         this.startpos = startpos;
27                         this.str = str.Substring (startpos);
28                         this.element = null;
29                 }
30
31                 public object Current 
32                 {
33                         get {
34                                 if (element == null) {
35                                         throw new InvalidOperationException ();
36                                 }
37
38                                 return(element);
39                         }
40                 }
41
42                 public int ElementIndex 
43                 {
44                         get {
45                                 if (element == null) {
46                                         throw new InvalidOperationException ();
47                                 }
48
49                                 return(elementindex + startpos);
50                         }
51                 }
52
53                 public string GetTextElement()
54                 {
55                         if (element == null) {
56                                 throw new InvalidOperationException ();
57                         }
58
59                         return(element);
60                 }
61
62                 public bool MoveNext()
63                 {
64                         elementindex = index + 1;
65                         
66                         if (elementindex < str.Length) {
67                                 element = StringInfo.GetNextTextElement (str, elementindex);
68                                 index += element.Length;
69                                 
70                                 return(true);
71                         } else {
72                                 element = null;
73
74                                 return(false);
75                         }
76                 }
77
78                 public void Reset()
79                 {
80                         element = null;
81                         index = -1;
82                 }
83         }
84 }