| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- 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;
- }
- }
- }
|