Ejemplo n.º 1
0
        /// <summary>
        /// Read close bracket
        /// </summary>
        public static bool TryProceedCloseBracket(List <BaseFormulaNode> nodes, ReadOnlySpan <char> formula, BracketCounters negativeBracketCounters, ref int index)
        {
            if (formula[index] != CLOSE_BRACKET_CHAR)
            {
                return(false);
            }

            // Add bracket
            var bracket = AddCloseBracket(nodes);

            // If there is unary minus, we must add close bracket
            if (negativeBracketCounters.Proceed(bracket))
            {
                AddCloseBracket(nodes);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Read open bracket
        /// </summary>
        public static bool TryProceedOpenBracket(List <BaseFormulaNode> nodes, ReadOnlySpan <char> formula, BracketCounters negativeBracketCounters, ref int index)
        {
            // Read unary minus
            var localIndex = UnaryMinusReader.ReadUnaryMinus(nodes, formula, index, out var isNegativeLocal);

            // Check out of range
            if (localIndex >= formula.Length)
            {
                return(false);
            }

            // Check open bracket
            if (formula[localIndex] == OPEN_BRACKET_CHAR)
            {
                if (isNegativeLocal)
                {
                    AddAdditionalNodesForUnaryMinus(nodes);
                }

                // Add bracket
                var bracket = AddOpenBracket(nodes);

                // Is unary minus
                if (isNegativeLocal)
                {
                    negativeBracketCounters.CreateNewCounter();
                }
                else
                {
                    negativeBracketCounters.Proceed(bracket);
                }

                index = localIndex;
                return(true);
            }

            return(false);
        }