示例#1
0
        /// <summary>
        /// scan for the first sequence of chars in string after initial whitespace.
        /// </summary>
        /// <param name="InString"></param>
        /// <param name="InWhitespace"></param>
        /// <param name="InMaxReturnChars"></param>
        /// <returns></returns>
        public static ScanStringResults ScanFirstChars(
            string InString, Whitespace InWhitespace, int InMaxReturnChars)
        {
            int ix = 0;
            ScanStringResults res = null;

            ScanCharResults cr = Scanner.ScanNotEqual(InString, 0, InWhitespace.WhitespaceChars);

            if (cr.ResultPos == -1)
            {
                ix = 0;
            }
            else
            {
                ix = cr.ResultPos;
            }

            if (ix >= InString.Length)
            {
                res = new ScanStringResults(-1);
            }
            else
            {
                string fsChars = Stringer.SubstringLenient(InString, ix, InMaxReturnChars);
                res = new ScanStringResults(fsChars, ix);
            }

            return(res);
        }
示例#2
0
 public ScanNonWordxResults(
     TextTraits InTextTraits, ScannerNonWord InNonWord, ScanCharResults InCharResults)
 {
     mTextTraits  = InTextTraits;
     mNonWord     = InNonWord;
     mCharResults = InCharResults;
 }
示例#3
0
            public ScanNonWordResults(ScanCharResults InScanChar)
            {
                mPosition = InScanChar.ResultPos;

                if (InScanChar.IsNotFound == true)
                {
                    mNonWordChar = null;
                }
                else
                {
                    mNonWordChar = InScanChar.ResultChar;
                }

                mDelimClass    = DelimClassification.None;
                mNonWordString = null;
            }
示例#4
0
        /// <summary>
        /// Scan the bounded string for any of the pattern characters,
        /// bypassing quoted strings within the scan space.
        /// </summary>
        /// <param name="InBounded"></param>
        /// <param name="InBx"></param>
        /// <param name="InPatternChars"></param>
        /// <param name="InQem"></param>
        /// <returns></returns>
        public static ScanCharResults ScanEqualAny_BypassQuoted(
            BoundedString InBounded,
            int InBx,
            char[] InPatternChars,
            QuoteEncapsulation InQem)
        {
            ScanCharResults res;
            int             Fx;

            char[] patternChars = Arrayer.Concat <char>(InPatternChars, new char[] { '"', '\'' });
            int    Ix           = InBx;

            while (true)
            {
                res = ScanEqualAny(InBounded, Ix, patternChars);
                if (res.ResultPos == -1)
                {
                    break;
                }
                else if (IsOpenQuoteChar(res.ResultChar) == true)
                {
                    Fx = ScanCloseQuote(InBounded, res.ResultPos, InQem);
                    if (Fx == -1)
                    {
                        throw new ApplicationException("End of quoted string not found");
                    }
                    else if (Fx == InBounded.Ex)
                    {
                        res = new ScanCharResults(-1);
                        break;
                    }
                    else
                    {
                        Ix = Fx + 1;
                    }
                }
                else
                {
                    break;
                }
            }

            return(res);
        }
示例#5
0
        /// <summary>
        /// Scan string for any of the pattern strings in ScanPatterns.
        /// </summary>
        /// <param name="InString"></param>
        /// <param name="InBx"></param>
        /// <param name="InLx"></param>
        /// <param name="InPatterns"></param>
        /// <returns></returns>
        public static ScanPatternResults ScanEqualAny(
            string InString, int InIx, int InLx, ScanPatterns InPatterns)
        {
            ScanPattern        pat = null;
            ScanPatternResults spr = null;
            int ix = InIx;
            int ex = InIx + InLx - 1;

            while (true)
            {
                spr = null;
                int remLx = ex - ix + 1;
                if (remLx <= 0)
                {
                    break;
                }

                ScanCharResults scr = ScanEqualAny(
                    InString, ix, remLx, InPatterns.LeadChars);
                if (scr.IsNotFound == true)
                {
                    spr = new ScanPatternResults(-1);
                    break;
                }

                pat = InPatterns.FindPatternAtSubstring(InString, scr.ResultPos, ex);
                if (pat != null)
                {
                    spr = new ScanPatternResults(scr.ResultPos, pat);
                    break;
                }

                // advance ix to resume scan after the found lead char.
                ix = scr.ResultPos + 1;
            }

            return(spr);
        }
示例#6
0
        public static Tuple <ScanPattern, int> ScanEqualAny(
            string Text, int Start, ScanPatterns Patterns)
        {
            ScanPattern pat = null;
            int         ix  = Start;

            while (true)
            {
                int remLx = Text.Length - ix;
                if (remLx <= 0)
                {
                    ix = -1;
                    break;
                }

                ScanCharResults scr = ScanEqualAny(
                    Text, ix, remLx, Patterns.LeadChars);
                if (scr.IsNotFound == true)
                {
                    ix = -1;
                    break;
                }

                ix  = scr.ResultPos;
                pat = Patterns.FindPatternAtSubstring(Text, ix, Text.Length - 1);
                if (pat != null)
                {
                    break;
                }

                // advance ix to resume scan after the found lead char.
                ix = ix + 1;
            }

            return(new Tuple <ScanPattern, int>(pat, ix));
        }
示例#7
0
 public ScanNonWordxResults(TextTraits InTextTraits)
 {
     mTextTraits  = InTextTraits;
     mNonWord     = null;
     mCharResults = new ScanCharResults();
 }
示例#8
0
        // -------------------- ScanWord_IsolateWord ---------------------------
        private static void ScanWord_IsolateWord(
            string InString,
            int InBx,
            ref WordCursor InOutResults,
            TextTraits InTraits)
        {
            int    Bx, Fx, Ix, Lx;
            string word;

            Bx = InBx;
            char ch1 = InString[Bx];

            // is quoted. the word runs to the closing quote.
            if (IsOpenQuoteChar(ch1) == true)
            {
                Ix = ScanCloseQuote(InString, Bx, InTraits.QuoteEncapsulation);
                if (Ix == -1)
                {
                    throw(new ApplicationException("Closing quote not found starting at position " +
                                                   Bx + " in " + InString));
                }
                Lx   = Ix - Bx + 1;
                word = InString.Substring(Bx, Lx);
                InOutResults.SetWord(word, WordClassification.Quoted, Bx);
                return;
            }

            // look for a brace or delim character.
            char[]          combo   = AcCommon.Concat(InTraits.DelimChars, InTraits.BraceChars);
            ScanCharResults results = ScanEqual(InString, Bx, combo);

            Fx  = results.ResultPos;
            ch1 = results.ResultChar;

            // found a brace char
            if ((InTraits.IsOpenBraceChar(ch1) == true) &&
                (InTraits.IsDelimChar(ch1) == false))
            {
                Ix = ScanCloseBrace(InString, Fx);
                if (Ix == -1)
                {
                    throw(new ApplicationException("Closing brace not found starting at position " +
                                                   Fx + " in " + InString));
                }
                Lx   = Ix - Bx + 1;
                word = InString.Substring(Bx, Lx);
                if (Bx == Fx)
                {
                    InOutResults.SetWord(word, WordClassification.Braced, Bx);
                }
                else
                {
                    InOutResults.SetWord(word, WordClassification.NameBraced, Bx, ch1);
                }
            }

            // no delim found. all word to the end of the string.
            else if (Fx == -1)
            {
                word = InString.Substring(Bx);
                InOutResults.SetWord(word, WordClassification.Name, Bx);
            }

            // delim is same position as the word.  so there is no word, only a delim.
            else if (Fx == Bx)
            {
                InOutResults.SetNullWord( );
            }

            // we have a word that ends with a delim.
            else
            {
                Lx   = Fx - Bx;
                word = InString.Substring(Bx, Lx);
                InOutResults.SetWord(word, WordClassification.Name, Bx);
            }
        }
示例#9
0
        // -------------------- ScanWord_IsolateDelim ---------------------------
        private static void ScanWord_IsolateDelim(
            string InString,
            int InBx,
            ref WordCursor InOutResults,
            TextTraits InTraits)
        {
            int    Bx, Lx;
            string delim;

            // setup the start of the delim.
            if (InOutResults.WordBx == -1)
            {
                Bx = InBx;
            }
            else
            {
                Bx = InOutResults.WordEx + 1;
            }

            // word went to the end of the string.
            if (Bx >= InString.Length)
            {
                Bx = -1;
            }

            // we have a delimiter of some kind.
            if (Bx != -1)
            {
                InOutResults.DelimIsWhitespace = false;

                // the delim is a hard delim ( not whitespace )
                char ch1 = InString[Bx];
                if (AcCommon.Contains(InTraits.WhitespaceChars, ch1) == false)
                {
                    Lx    = 1;
                    delim = InString.Substring(Bx, Lx);
                    InOutResults.SetDelim(delim, Bx);
                }

                // is a soft delim ( whitespace ). Look for hard delim after the ws.
                else
                {
                    ScanCharResults scanResults =
                        ScanNotEqual(InString, Bx, InTraits.WhitespaceChars);
                    if ((scanResults.ResultPos != -1) &&
                        (AcCommon.Contains(InTraits.DelimChars, scanResults.ResultChar)))
                    {
                        Lx    = 1;
                        delim = AcCommon.CharToString(scanResults.ResultChar);
                        InOutResults.SetDelim(delim, scanResults.ResultPos);
                    }

                    // the whitespace char is the delim of record.
                    else
                    {
                        Lx    = 1;
                        delim = InString.Substring(Bx, Lx);
                        InOutResults.SetDelim(delim, Bx);
                        InOutResults.DelimIsWhitespace = true;
                    }
                }
            }
        }