1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 |
|
---|
6 | namespace Lextm.SharpSnmpLib.Mib
|
---|
7 | {
|
---|
8 | public class SymbolList : List<Symbol>
|
---|
9 | {
|
---|
10 | public class SymbolEnumerator : ISymbolEnumerator
|
---|
11 | {
|
---|
12 | private SymbolList _list = null;
|
---|
13 | private int _index = -1;
|
---|
14 |
|
---|
15 | internal SymbolEnumerator(SymbolList list)
|
---|
16 | {
|
---|
17 | if (list == null)
|
---|
18 | {
|
---|
19 | throw new ArgumentNullException("lexer");
|
---|
20 | }
|
---|
21 |
|
---|
22 | _list = list;
|
---|
23 | }
|
---|
24 |
|
---|
25 | #region ISymbolEnumerator Member
|
---|
26 |
|
---|
27 | public bool PutBack(Symbol item)
|
---|
28 | {
|
---|
29 | if ((_index < 0) || (_index >= _list.Count) || (item != _list[_index]))
|
---|
30 | {
|
---|
31 | throw new ArgumentException(@"wrong last symbol", "last");
|
---|
32 | //return false;
|
---|
33 | }
|
---|
34 |
|
---|
35 | _index--;
|
---|
36 | return true;
|
---|
37 | }
|
---|
38 |
|
---|
39 | #endregion
|
---|
40 |
|
---|
41 | #region IEnumerator<Symbol> Member
|
---|
42 |
|
---|
43 | public Symbol Current
|
---|
44 | {
|
---|
45 | get
|
---|
46 | {
|
---|
47 | if ((_index >= 0) && (_index <= _list.Count))
|
---|
48 | {
|
---|
49 | return _list[_index];
|
---|
50 | }
|
---|
51 |
|
---|
52 | return null;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | #endregion
|
---|
57 |
|
---|
58 | #region IDisposable Member
|
---|
59 |
|
---|
60 | public void Dispose()
|
---|
61 | {
|
---|
62 | }
|
---|
63 |
|
---|
64 | #endregion
|
---|
65 |
|
---|
66 | #region IEnumerator Member
|
---|
67 |
|
---|
68 | object System.Collections.IEnumerator.Current
|
---|
69 | {
|
---|
70 | get { return this.Current; }
|
---|
71 | }
|
---|
72 |
|
---|
73 | public bool MoveNext()
|
---|
74 | {
|
---|
75 | _index++;
|
---|
76 | return (_index >= 0) && (_index < _list.Count);
|
---|
77 | }
|
---|
78 |
|
---|
79 | public void Reset()
|
---|
80 | {
|
---|
81 | _index = -1;
|
---|
82 | }
|
---|
83 |
|
---|
84 | #endregion
|
---|
85 | }
|
---|
86 |
|
---|
87 | /// <summary>
|
---|
88 | /// Initializes a new instance of the <see cref="SymbolList"/> class.
|
---|
89 | /// </summary>
|
---|
90 | public SymbolList()
|
---|
91 | {
|
---|
92 | }
|
---|
93 |
|
---|
94 | public ISymbolEnumerator GetSymbolEnumerator()
|
---|
95 | {
|
---|
96 | return new SymbolEnumerator(this);
|
---|
97 | }
|
---|
98 |
|
---|
99 | public string Join(string separator)
|
---|
100 | {
|
---|
101 | if (separator == null)
|
---|
102 | separator = "";
|
---|
103 |
|
---|
104 | StringBuilder result = new StringBuilder();
|
---|
105 |
|
---|
106 | foreach (Symbol s in this)
|
---|
107 | {
|
---|
108 | result.Append(s);
|
---|
109 | result.Append(separator);
|
---|
110 | }
|
---|
111 |
|
---|
112 | if (result.Length > 0)
|
---|
113 | {
|
---|
114 | result.Length -= separator.Length;
|
---|
115 | }
|
---|
116 |
|
---|
117 | return result.ToString();
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | public static class SymbolEnumeratorExtension
|
---|
122 | {
|
---|
123 | public static Symbol NextSymbol(this IEnumerator<Symbol> enumerator)
|
---|
124 | {
|
---|
125 | if (enumerator.MoveNext())
|
---|
126 | {
|
---|
127 | return enumerator.Current;
|
---|
128 | }
|
---|
129 |
|
---|
130 | return null;
|
---|
131 | }
|
---|
132 |
|
---|
133 | public static Symbol NextNonEOLSymbol(this IEnumerator<Symbol> enumerator)
|
---|
134 | {
|
---|
135 | while (enumerator.MoveNext())
|
---|
136 | {
|
---|
137 | if (enumerator.Current != Symbol.EOL)
|
---|
138 | {
|
---|
139 | return enumerator.Current;
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | return null;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | }
|
---|