private bool ParseDecimal(TextParser input, FormatSpecifier spec)
{
int radix = 10;
// Skip any whitespace
input.MovePastWhitespace();
// Parse leading sign
int start = input.Position;
if (input.Peek() == '+' || input.Peek() == '-')
{
input.MoveAhead();
}
else if (input.Peek() == '0')
{
if (Char.ToLower(input.Peek(1)) == 'x')
{
radix = 16;
input.MoveAhead(2);
}
else
{
radix = 8;
input.MoveAhead();
}
}
// Parse digits
while (IsValidDigit(input.Peek(), radix))
input.MoveAhead();
// Don't exceed field width
if (spec.Width > 0)
{
int count = input.Position - start;
if (spec.Width < count)
input.MoveAhead(spec.Width - count);
}
// Extract token
if (input.Position > start)
{
if (!spec.NoResult)
{
if (spec.Type == Types.Decimal)
AddSigned(input.Extract(start, input.Position), spec.Modifier, radix);
else
AddUnsigned(input.Extract(start, input.Position), spec.Modifier, radix);
}
return true;
}
return false;
}