public int Parse(string input, string format)
{
TextParser inp = new TextParser(input);
TextParser fmt = new TextParser(format);
List<object> results = new List<object>();
FormatSpecifier spec = new FormatSpecifier();
int count = 0;
// Clear any previous results
Results.Clear();
// Process input string as indicated in format string
while (!fmt.EndOfText && !inp.EndOfText)
{
if (ParseFormatSpecifier(fmt, spec))
{
// Found a format specifier
TypeParser parser = null;
foreach(TypeParser tp in _typeParsers)
if (tp.Type == spec.Type)
{
parser = tp;
break;
}
if (parser == null)
break;
if (parser.Parser(inp, spec))
count++;
else
break;
}
else if (Char.IsWhiteSpace(fmt.Peek()))
{
// Whitespace
inp.MovePastWhitespace();
fmt.MoveAhead();
}
else if (fmt.Peek() == inp.Peek())
{
// Matching character
inp.MoveAhead();
fmt.MoveAhead();
}
else break; // Break at mismatch
}
// Return number of fields successfully parsed
return count;
}