Exemple #1
0
        // ------------------------ ScanCloseBrace -------------------------
        // todo: pass TextTraits to a version of this method. Use recursion for each brace
        //       char found.
        /// <summary>
        /// scan for closing brace char that matches the start at open brace char.
        /// </summary>
        /// <param name="InString"></param>
        /// <param name="InBx">scan start position</param>
        /// <param name="InEx">end position in string</param>
        /// <param name="InQem"></param>
        /// <returns></returns>
        public static int ScanCloseBrace(
            string InString, int InBx, int InEx, QuoteEncapsulation InQem)
        {
            char openBraceChar = InString[InBx];
            char closeBraceChar = AcCommon.CalcCloseBraceChar(openBraceChar);
            int  Ix = InBx, Fx = 0;
            int  ParenLevel = 1;

            if (InEx >= InString.Length)
            {
                throw new ApplicationException("ScanCloseBrace end pos exceeds string length");
            }

            while (true)
            {
                ++Ix;
                if (Ix > InEx)
                {
                    Ix = -1;
                    break;
                }

                char ch1 = InString[Ix];
                if (ch1 == openBraceChar)
                {
                    ++ParenLevel;
                }
                else if (ch1 == closeBraceChar)
                {
                    --ParenLevel;
                    if (ParenLevel == 0)
                    {
                        break;
                    }
                }
                else if (IsOpenQuoteChar(ch1) == true)
                {
                    Fx = ScanCloseQuote(InString, Ix, InQem);
                    Ix = Fx;
                }
            }
            return(Ix);
        }
Exemple #2
0
        // ------------------------ ScanCloseParen -------------------------
        public int ScanCloseParen(int InBx)
        {
            char OpenParenChar = mCmds[InBx];
            char CloseParenChar = AcCommon.CalcCloseBraceChar(mCmds[InBx]);
            int  Ix = InBx, Fx = 0;
            int  Lx         = mCmds.Length;
            int  ParenLevel = 1;

            while (true)
            {
                ++Ix;
                if (Ix >= Lx)
                {
                    throw(new TextScanException(
                              "ScanCloseParen", "Close paren not found."));
                }

                char ch1 = mCmds[Ix];
                if (ch1 == OpenParenChar)
                {
                    ++ParenLevel;
                }
                else if (ch1 == CloseParenChar)
                {
                    --ParenLevel;
                    if (ParenLevel == 0)
                    {
                        break;
                    }
                }
                else if (IsOpenParenChar(Ix) == true)
                {
                    Fx = ScanCloseParen(Ix);
                    Ix = Fx;
                }
                else if (IsOpenQuoteChar(Ix) == true)
                {
                    Fx = ScanCloseQuote(Ix);
                    Ix = Fx;
                }
            }
            return(Ix);
        }
Exemple #3
0
        // ------------------------ ScanCloseBrace -------------------------
        // todo: pass TextTraits to a version of this method. Use recursion for each brace
        //       char found.
        public static int ScanCloseBrace(
            string InString, int InBx, QuoteEncapsulation InQem)
        {
            char openBraceChar = InString[InBx];
            char closeBraceChar = AcCommon.CalcCloseBraceChar(openBraceChar);
            int  Ix = InBx, Fx = 0;
            int  Lx         = InString.Length;
            int  ParenLevel = 1;

            while (true)
            {
                ++Ix;
                if (Ix >= Lx)
                {
                    throw(new TextException(
                              "ScanCloseBrace", "Close brace not found."));
                }

                char ch1 = InString[Ix];
                if (ch1 == openBraceChar)
                {
                    ++ParenLevel;
                }
                else if (ch1 == closeBraceChar)
                {
                    --ParenLevel;
                    if (ParenLevel == 0)
                    {
                        break;
                    }
                }
                else if (IsOpenQuoteChar(ch1) == true)
                {
                    Fx = ScanCloseQuote(InString, Ix, InQem);
                    Ix = Fx;
                }
            }
            return(Ix);
        }