void ReadNumber (int ch)
{
elements.Push (new ElementInfo (next_element, "number"));
content_stored = true;
int init = ch;
int prev;
bool floating = false, exp = false;
StringBuilder sb = new StringBuilder ();
bool cont = true;
do {
sb.Append ((char) ch);
prev = ch;
ch = ReadChar ();
if (prev == '-' && !IsNumber (ch)) // neither '.', '-' or '+' nor anything else is valid
throw XmlError ("Invalid JSON number");
switch (ch) {
case 'e':
case 'E':
if (exp)
throw XmlError ("Invalid JSON number token. Either 'E' or 'e' must not occur more than once");
if (!IsNumber (prev))
throw XmlError ("Invalid JSON number token. only a number is valid before 'E' or 'e'");
exp = true;
break;
case '.':
if (floating)
throw XmlError ("Invalid JSON number token. '.' must not occur twice");
if (exp)
throw XmlError ("Invalid JSON number token. '.' must not occur after 'E' or 'e'");
floating = true;
break;
case '+':
case '-':
if (prev == 'E' || prev == 'e')
break;
goto default;
default:
if (!IsNumber (ch)) {
PushbackChar (ch);
cont = false;
}
break;
}
} while (cont);
if (!IsNumber (prev)) // only number is valid at the end
throw XmlError ("Invalid JSON number");
simple_value = sb.ToString ();
if (init == '0' && !floating && !exp && simple_value != "0")
throw XmlError ("Invalid JSON number");
}