示例#1
0
        private static bool TryReadHatPower(string text, ref int pos, out int power)
        {
            if (text[pos] != '^')
            {
                // leaving this even if it is a try method. Getting here means something should have been checked before
                throw new InvalidOperationException("Check that there is a hat power to read before calling this");
            }

            pos++;
            WhiteSpaceReader.TryRead(text, ref pos);

            var ps = OperatorReader.TryReadSign(text, ref pos);

            if (ps == Sign.None)
            {
                ps = Sign.Positive;
            }

            if (OperatorReader.TryReadSign(text, ref pos) != Sign.None)
            {
                // not allowing a^--2 as it is most likely a typo
                power = 0;
                return(false);
            }

            WhiteSpaceReader.TryRead(text, ref pos);
            if (IntReader.TryReadInt32(text, ref pos, out power))
            {
                power *= (int)ps;
                return(true);
            }

            power = 0;
            return(false);
        }
示例#2
0
        private static bool TrySkipIntegerDigits(string text, ref int pos, NumberStyles styles, NumberFormatInfo format)
        {
            if (pos == text.Length)
            {
                return(false);
            }

            var start = pos;

            if (format?.NumberDecimalSeparator != null &&
                Skipper.TrySkip(text, ref pos, format.NumberDecimalSeparator))
            {
                if (!IntReader.IsDigit(text, pos))
                {
                    pos = start;
                    return(false);
                }

                pos = start;
                return(true);
            }

            if (!IntReader.IsDigit(text[pos]))
            {
                return(false);
            }

            while (pos < text.Length)
            {
                var i = text[pos] - '0';
                if (i >= 0 && i <= 9)
                {
                    pos++;
                    continue;
                }

                if ((styles & NumberStyles.AllowThousands) != 0)
                {
                    if (format?.NumberDecimalSeparator != null &&
                        Skipper.TrySkip(text, ref pos, format.NumberGroupSeparator))
                    {
                        continue;
                    }
                }

                break;
            }

            return(pos - start < 310);
        }
示例#3
0
 private static bool TrySkipExponentDigits(string text, ref int pos)
 {
     return(IntReader.TrySkipDigits(text, ref pos));
 }
示例#4
0
 // ReSharper disable once UnusedMethodReturnValue.Local
 private static bool TrySkipFractionDigits(string text, ref int pos)
 {
     return(IntReader.TrySkipDigits(text, ref pos));
 }