internal void Validate(bool condition, string message) { if (condition) { throw MibException.Create(message, this); } }
internal void Assert(bool condition, string message) { if (!condition) { throw MibException.Create(message, this); } }
internal void ParseOidValue(out string parent, out uint value) { parent = null; value = 0; Symbol previous = null; Symbol temp = NextNonEOLSymbol; temp.Expect(Symbol.OpenBracket); StringBuilder longParent = new StringBuilder(); temp = NextNonEOLSymbol; longParent.Append(temp); while ((temp = NextNonEOLSymbol) != null) { if (temp == Symbol.OpenParentheses) { longParent.Append(temp); temp = NextNonEOLSymbol; bool succeed = UInt32.TryParse(temp.ToString(), out value); temp.Validate(!succeed, "not a decimal"); longParent.Append(temp); temp = NextNonEOLSymbol; temp.Expect(Symbol.CloseParentheses); longParent.Append(temp); continue; } if (temp == Symbol.CloseBracket) { parent = longParent.ToString(); return; } bool succeeded = UInt32.TryParse(temp.ToString(), out value); if (succeeded) { // numerical way while ((temp = NextNonEOLSymbol) != Symbol.CloseBracket) { longParent.Append(".").Append(value); succeeded = UInt32.TryParse(temp.ToString(), out value); temp.Validate(!succeeded, "not a decimal"); } temp.Expect(Symbol.CloseBracket); parent = longParent.ToString(); return; } longParent.Append("."); longParent.Append(temp); temp = NextNonEOLSymbol; temp.Expect(Symbol.OpenParentheses); longParent.Append(temp); temp = NextNonEOLSymbol; succeeded = UInt32.TryParse(temp.ToString(), out value); temp.Validate(!succeeded, "not a decimal"); longParent.Append(temp); temp = NextNonEOLSymbol; temp.Expect(Symbol.CloseParentheses); longParent.Append(temp); previous = temp; } throw MibException.Create("end of file reached", previous); }
public static void ParseOidValue(ISymbolEnumerator symbols, out string parent, out uint value) { parent = null; value = 0; Symbol current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.OpenBracket); Symbol previous = null; StringBuilder longParent = new StringBuilder(); current = symbols.NextNonEOLSymbol(); longParent.Append(current); while ((current = symbols.NextNonEOLSymbol()) != null) { bool succeeded; if (current == Symbol.OpenParentheses) { longParent.Append(current); current = symbols.NextNonEOLSymbol(); succeeded = UInt32.TryParse(current.ToString(), out value); current.Assert(succeeded, "not a decimal"); longParent.Append(current); current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.CloseParentheses); longParent.Append(current); continue; } if (current == Symbol.CloseBracket) { parent = longParent.ToString(); return; } succeeded = UInt32.TryParse(current.ToString(), out value); if (succeeded) { // numerical way while ((current = symbols.NextNonEOLSymbol()) != Symbol.CloseBracket) { longParent.Append(".").Append(value); succeeded = UInt32.TryParse(current.ToString(), out value); current.Assert(succeeded, "not a decimal"); } current.Expect(Symbol.CloseBracket); parent = longParent.ToString(); return; } longParent.Append("."); longParent.Append(current); current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.OpenParentheses); longParent.Append(current); current = symbols.NextNonEOLSymbol(); succeeded = UInt32.TryParse(current.ToString(), out value); current.Assert(succeeded, "not a decimal"); longParent.Append(current); current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.CloseParentheses); longParent.Append(current); previous = current; } throw MibException.Create("end of file reached", previous); }