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