コード例 #1
0
        public Equation GetShorted(Equation equation)
        {
            int    level = 1;
            string higherLevelEquation = "";

            equation.RemoveAt(0);

            while (equation.Count > 0)
            {
                char c = equation[0];
                equation.RemoveAt(0);

                if (IsBeginLook(c))
                {
                    level++;
                }
                else if (IsEndLook(c))
                {
                    level--;
                }

                if (level == 0)
                {
                    return(new Equation(higherLevelEquation));
                }

                higherLevelEquation += c;
            }

            return(new Equation());
        }
コード例 #2
0
        public override bool Matches(Equation equation)
        {
            if (!startDoubleChars.Contains(equation[0]))
            {
                return(false);
            }

            string simpleValueText = "";
            double preValue = -1, curValue;

            do
            {
                simpleValueText += equation[0];

                if (!double.TryParse(simpleValueText, out curValue))
                {
                    if (preValue == -1)
                    {
                        return(false);
                    }

                    Value = preValue;
                    return(true);
                }

                equation.RemoveAt(0);
                preValue = curValue;
            } while (equation.Count > 0 && allDoubleChars.Contains(equation[0]));

            Value = curValue;
            return(true);
        }
コード例 #3
0
        private static bool LooksLike(Equation equation, string look)
        {
            if (!equation.ToString().ToLower().StartsWith(look))
            {
                return(false);
            }

            for (int i = 0; i < look.Length; i++)
            {
                equation.RemoveAt(0);
            }

            return(true);
        }
コード例 #4
0
        private void GoThroughEquation()
        {
            while (equation.Count > 0)
            {
                Part addPart;

                if (IsPart(out addPart))
                {
                    parts.Add(addPart);
                }
                else
                {
                    equation.RemoveAt(0);
                }
            }
        }