private static string ScanForNumber(string input, int offset) { int startIndex = offset; if (offset >= input.Length) { return((string)null); } char c1 = input[offset]; if (!char.IsDigit(c1) && c1 != '.') { return((string)null); } bool flag1 = true; bool flag2 = false; bool flag3 = false; if (c1 == '.') { if (offset + 1 >= input.Length || !char.IsDigit(input[offset + 1])) { return((string)null); } flag1 = false; } if (c1 == '0' && offset + 1 < input.Length && char.ToUpperInvariant(input[offset + 1]) == 'X') { ++offset; flag2 = true; flag1 = false; } while (++offset < input.Length) { char c2 = input[offset]; if (!char.IsDigit(c2) && (!flag2 || char.ToUpperInvariant(c2) > 'F' || char.ToUpperInvariant(c2) < 'A')) { if (c2 == '.') { if (flag1 && (offset + 1 >= input.Length || input[offset + 1] != '.')) { flag1 = false; } else { break; } } else if (char.ToUpperInvariant(c2) == 'E' && !flag3) { if (offset + 1 < input.Length && (input[offset + 1] == '+' || SpecialCharacters.IsDash(input[offset + 1]))) { ++offset; } flag3 = true; flag1 = false; } else { break; } } } if (offset < input.Length) { switch (char.ToUpperInvariant(input[offset])) { case 'D': case 'L': ++offset; break; } } if (NumberTokenReader.IsMultiplier(input, offset)) { offset += 2; } return(input.Substring(startIndex, offset - startIndex)); }
private static object ConvertToNumber(string str, Tokenizer tokenizer) { bool flag1 = false; bool flag2 = false; bool flag3 = false; bool flag4 = false; long num = 1; str = NumberTokenReader.ConvertDash(str); if (str.IndexOf("0x", 0, StringComparison.OrdinalIgnoreCase) >= 0) { flag1 = true; } if (!flag1 && (str.IndexOf('.', 0) >= 0 || str.IndexOf("e", 0, StringComparison.OrdinalIgnoreCase) >= 0)) { flag4 = true; } if (NumberTokenReader.IsMultiplier(str, str.Length - 2)) { switch (char.ToUpperInvariant(str[str.Length - 2])) { case 'G': num = 1073741824L; str = str.Substring(0, str.Length - 2); break; case 'K': num = 1024L; str = str.Substring(0, str.Length - 2); break; case 'M': num = 1048576L; str = str.Substring(0, str.Length - 2); break; case 'P': num = 1125899906842624L; str = str.Substring(0, str.Length - 2); break; case 'T': num = 1099511627776L; str = str.Substring(0, str.Length - 2); break; } } char upperInvariant = char.ToUpperInvariant(str[str.Length - 1]); if (upperInvariant == 'L') { flag2 = true; str = str.Substring(0, str.Length - 1); } else if (!flag1 && upperInvariant == 'D') { flag3 = true; str = str.Substring(0, str.Length - 1); } Exception innerException; try { if (flag3) { return((object)(Decimal.Parse(str, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, (IFormatProvider)NumberFormatInfo.InvariantInfo) * (Decimal)num)); } if (flag2) { return((object)checked ((long)LanguagePrimitives.ConvertTo((object)str, typeof(long), (IFormatProvider)NumberFormatInfo.InvariantInfo) * num)); } if (flag4) { return((object)(double.Parse(str, (IFormatProvider)NumberFormatInfo.InvariantInfo) * (double)num)); } try { return((object)checked ((int)LanguagePrimitives.ConvertTo((object)str, typeof(int), (IFormatProvider)NumberFormatInfo.InvariantInfo) * (int)num)); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); } try { return((object)checked ((long)LanguagePrimitives.ConvertTo((object)str, typeof(long), (IFormatProvider)NumberFormatInfo.InvariantInfo) * num)); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); } try { return((object)((Decimal)LanguagePrimitives.ConvertTo((object)str, typeof(Decimal), (IFormatProvider)NumberFormatInfo.InvariantInfo) * (Decimal)num)); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); } return((object)((double)LanguagePrimitives.ConvertTo((object)str, typeof(double), (IFormatProvider)NumberFormatInfo.InvariantInfo) * (double)num)); } catch (OverflowException ex) { innerException = (Exception)ex; } catch (FormatException ex) { innerException = (Exception)ex; } catch (PSInvalidCastException ex) { innerException = (Exception)ex; } if (innerException != null) { if (tokenizer != null) { tokenizer.Parser.ReportExceptionWithInnerException((object)str, typeof(ParseException), tokenizer.PositionToken(), "BadNumericConstant", innerException, (object)innerException.Message); } else { throw InterpreterError.NewInterpreterExceptionWithInnerException((object)str, typeof(RuntimeException), (Token)null, "BadNumericConstant", innerException, (object)innerException.Message); } } return((object)null); }