Esempio n. 1
0
        // ------------------------ ScanFirstWord -------------------------
        public static WordCursor ScanFirstWord(string InString, TextTraits InTraits)
        {
            BoundedString boundedString = new BoundedString(InString);
            WordCursor    res           = ScanFirstWord(boundedString, InTraits);

            return(res);
        }
Esempio n. 2
0
        /// <summary>
        /// Scan with the bounded string for a char equal any of the pattern characters.
        /// </summary>
        /// <param name="InBounded"></param>
        /// <param name="InBx"></param>
        /// <param name="InPatternChars"></param>
        /// <returns></returns>
        public static ScanCharResults ScanEqualAny(
            BoundedString InBounded,
            int InBx,
            char[] InPatternChars)
        {
            int Ix;

            InBounded.ThrowBeforeBounds(InBx);

            int Lx = InBounded.Ex - InBx + 1;

            if (Lx <= 0)
            {
                Ix = -1;
            }
            else
            {
                Ix = InBounded.String.IndexOfAny(InPatternChars, InBx, Lx);
            }

            if (Ix == -1)
            {
                return(new ScanCharResults(-1));
            }
            else
            {
                char ch1 = InBounded.String[Ix];
                return(new ScanCharResults(ch1, Ix));
            }
        }
        /// <summary>
        /// calc if the char at location in string is a word char or not ( is not a
        /// NonWordChar )
        /// </summary>
        /// <param name="InBoundedString"></param>
        /// <param name="InIx"></param>
        /// <returns></returns>
        public bool IsWordChar(
            BoundedString InBoundedString, int InIx)
        {
            bool isWordChar = false;

            if (InBoundedString.IsOutsideBounds(InIx))
            {
                isWordChar = false;
            }

            else
            {
                ScanPattern pat = NonWordPatterns.FindPatternAtSubstring(
                    InBoundedString, InIx);
                if (pat == null)
                {
                    isWordChar = true;
                }
                else
                {
                    isWordChar = false;
                }
            }
            return(isWordChar);
        }
Esempio n. 4
0
        /// <summary>
        /// scan for pattern string within string.
        /// </summary>
        /// <param name="InBounded"></param>
        /// <param name="InBx"></param>
        /// <param name="InPattern"></param>
        /// <returns></returns>
        public static ScanStringResults ScanEqual(
            BoundedString InBounded, int InBx, string InPattern)
        {
            int Ix;

            InBounded.ThrowBeforeBounds(InBx);
            int remLx = InBounded.GetRemainingLength(InBx);

            if (remLx < InPattern.Length)
            {
                Ix = -1;
            }
            else
            {
                Ix = InBounded.String.IndexOf(InPattern, InBx);
            }

            if (Ix == -1)
            {
                return(new ScanStringResults(-1));
            }
            else
            {
                char ch1 = InBounded.String[Ix];
                return(new ScanStringResults(InPattern, Ix));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// calc if the char at location in string is a word char or not ( is not a
        /// NonWordChar )
        /// </summary>
        /// <param name="InBoundedString"></param>
        /// <param name="InIx"></param>
        /// <returns></returns>
        public bool IsWordChar(
            BoundedString InBoundedString, int InIx)
        {
            bool isWordChar = false;

            if (InBoundedString.IsOutsideBounds(InIx))
            {
                isWordChar = false;
            }

            else
            {
                var rv = NonWordPatterns.FindPatternAtSubstring(
                    InBoundedString, InIx);
                var pat     = rv.Item1;
                var matchLx = rv.Item2;

                if (pat == null)
                {
                    isWordChar = true;
                }
                else
                {
                    isWordChar = false;
                }
            }
            return(isWordChar);
        }
Esempio n. 6
0
        /// <summary>
        /// return the NonWord info of path sep char which is classified as being a
        /// path part delimiter ( it could be a division expression symbol )
        /// </summary>
        /// <param name="InBoundedString"></param>
        /// <param name="InIx"></param>
        /// <returns></returns>
        public ScanPattern GetPathPartDelim(BoundedString InBoundedString, int InIx)
        {
            ScanPattern pat     = null;
            int         matchLx = 0;

            if (InBoundedString.IsOutsideBounds(InIx))
            {
            }

            else if (IsPathSepChar(InBoundedString[InIx]) == true)
            {
                var rv = NonWordPatterns.MatchPatternsAtStringLocation(
                    InBoundedString.String, InIx, InBoundedString.Ex);
                pat     = rv.Item1;
                matchLx = rv.Item2;

                // the nonword is a path sep char. but is it a pathPart delim?
                // It is if there is a word char before or after the path sep char.
                // ex: /abc/efg vs. a = b / c ;
                if ((IsWordChar(InBoundedString, InIx - 1) == false) &&
                    (IsWordChar(InBoundedString, InIx + 1) == false))
                {
                    pat = null;
                }
            }
            return(pat);
        }
        // ------------------ ScanWord_IsolatedWord_CommentToEnd -------------------
        private static ScanPatternResults ScanWord_IsolateWord_CommentToEnd(
            BoundedString InBoundedString,
            int InWordBx,
            ref WordCursor InOutResults, TextTraits InTraits)
        {
            string             wordText;
            ScanPatternResults spr = null;

            // look for end of comment. ( either end of line or end of string )
            int fx = Scanner.ScanEqual(InBoundedString, InWordBx, Environment.NewLine).ResultPos;

            if (fx >= 0)
            {
                int Lx = fx - InWordBx;
                wordText = InBoundedString.Substring(InWordBx, Lx);
                ScanPattern pat =
                    InTraits.NonWordPatterns.FindPatternAtSubstring(InBoundedString, fx);
                spr = new ScanPatternResults(fx, pat);
            }
            else
            {
                wordText = InBoundedString.Substring(InWordBx);
                spr      = new ScanPatternResults(-1);
            }

            // store info on the word found in the return WordCursor argument.
            InOutResults.SetWord(wordText, WordClassification.CommentToEnd, InWordBx);

            // return value of method contains info on the word delim.
            return(spr);
        }
        // ----------------------- ScanWord_IsolatedWord_Braced -----------------------
        private static void ScanWord_IsolateWord_Braced(
            BoundedString InBoundedString,
            int InWordBx,
            ScanPatternResults InNonWordResults,
            ref WordCursor InOutResults,
            TextTraits InTraits)
        {
            string wordText;
            int    Lx, Ix;

            int braceIx = InNonWordResults.FoundPos;

            char braceChar = InNonWordResults.FoundPat.LeadChar;

            if (InTraits.BracedTreatment == ScannerBracedTreatment.Parts)
            {
                // a standalone open brace char. the brace char is the word ( and it will
                // also be the delim )
                if (InWordBx == braceIx)
                {
                    InOutResults.SetWord(
                        InNonWordResults.FoundPat.PatternValue,
                        WordClassification.OpenContentBraced, InWordBx, braceChar);
                }
                else
                {
                    wordText =
                        InBoundedString.String.Substring(InWordBx, braceIx - InWordBx);
                    InOutResults.SetWord(
                        wordText, WordClassification.OpenNamedBraced, InWordBx, braceChar);
                }
            }

            // the whole braced word.  braced word runs all the way to the closing brace.
            else if (InTraits.BracedTreatment == ScannerBracedTreatment.Whole)
            {
                Ix = ScanCloseBrace(
                    InBoundedString.String,
                    braceIx, InBoundedString.Ex, InTraits.QuoteEncapsulation);
                if (Ix == -1)
                {
                    throw new ApplicationException(
                              "Closing brace not found starting at position " +
                              braceIx + " in " + InBoundedString.String);
                }
                Lx       = Ix - InWordBx + 1;
                wordText = InBoundedString.String.Substring(InWordBx, Lx);
                if (InWordBx == braceIx)
                {
                    InOutResults.SetWord(
                        wordText, WordClassification.ContentBraced, InWordBx, braceChar);
                }
                else
                {
                    InOutResults.SetWord(
                        wordText, WordClassification.NamedBraced, InWordBx, braceChar);
                }
            }
        }
Esempio n. 9
0
        public static ScanPatternResults ScanEqualAny(
            BoundedString InString, int InIx, ScanPatterns InPatterns)
        {
            int lx = InString.Ex - InIx + 1;
            ScanPatternResults spr = ScanEqualAny(InString.String, InIx, lx, InPatterns);

            return(spr);
        }
        public static int ScanCloseQuote(
            BoundedString Text, int Bx, VerbatimLiteralPattern LitPattern)
        {
            char quoteChar = LitPattern.QuoteChar;



            return(-1);
        }
        // ------------------------ ScanNextWord -------------------------
        // Scans to the next word in the string. ( a word being the text bounded by the
        // delimeter and whitespace characters as spcfd in the TextTraits argument )
        // Return null when end of string.
        public static WordCursor ScanNextWord(
            string Text,
            WordCursor CurrentWord)
        {
            BoundedString boundedString = new BoundedString(Text);
            WordCursor    res           = ScanNextWord(boundedString, CurrentWord);

            return(res);
        }
Esempio n. 12
0
        // ------------------------ ScanFirstWord -------------------------
        public static WordCursor ScanFirstWord(
            BoundedString InBoundedString, TextTraits InTraits)
        {
            WordCursor csr = new WordCursor();

            csr.Position   = RelativePosition.Begin;
            csr.TextTraits = InTraits;
            WordCursor res = ScanNextWord(InBoundedString, csr);

            return(res);
        }
        /// <summary>
        /// calc if the word starting at InBx is part of a path.
        /// </summary>
        /// <param name="InBoundedString"></param>
        /// <param name="InTraits"></param>
        /// <param name="InBx"></param>
        /// <returns></returns>
        private static bool ScanWord_IsolateDelim_IsPathPart(
            BoundedString InBoundedString, TextTraits InTraits, int InBx)
        {
            bool rc = false;

            WordCursor csr = InBoundedString.PositionBefore(InBx, InTraits);

            csr = ScanNextWord(InBoundedString, csr);

            if ((csr.IsPathPart == true))
            {
                rc = true;
            }

            return(rc);
        }
Esempio n. 14
0
 // ----------------------------------- SetDelim ------------------------------------
 public void SetDelim(
     BoundedString InBoundedString,
     ScanPatternResults InScanResults, DelimClassification InDelimClass)
 {
     if (InScanResults.IsNotFound == true)
     {
         mDelim          = null;
         mDelimBx        = -1;
         this.DelimClass = DelimClassification.EndOfString;
     }
     else
     {
         SetDelim(
             InBoundedString, InScanResults.FoundPat.PatternValue, InScanResults.FoundPos,
             InDelimClass);
     }
 }
        // --------------------------- ScanWord_IsolateDelim_SetDelimIsWhitespace ----------
        private static void ScanWord_IsolateDelim_SetDelimIsWhitespace(
            BoundedString InBoundedString, TextTraits InTraits,
            WordCursor InOutResults, int InWsIx)
        {
            // store the actual string of whitespace characters. ( the whitespace can be
            // checked later to see if it contains tabs or newlines )
            ScanPatternResults spr = ScanNotEqual(
                InBoundedString.String, InWsIx, InBoundedString.Ex,
                InTraits.WhitespacePatterns);

            string delimVlu = spr.ScannedOverString;

            InOutResults.SetDelim(
                InBoundedString, delimVlu, InWsIx, DelimClassification.Whitespace);

            InOutResults.DelimIsWhitespace = true;
        }
Esempio n. 16
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);
        }
        // ----------------------- ScanWord_CalcStartBx ---------------------------
        // calc start position from which to start scan to the next word.
        private static int ScanWord_CalcStartBx(
            BoundedString BoundedString, WordCursor Word)
        {
            int Bx;

            switch (Word.Position)
            {
            case RelativePosition.Begin:
                Bx = BoundedString.Bx;
                break;

            case RelativePosition.Before:
                Bx = Word.ScanBx;
                break;

            case RelativePosition.After:
                Bx = Word.ScanEx + 1;
                break;

            case RelativePosition.At:
                Bx = Word.ScanEx + 1;
                break;

            case RelativePosition.End:
                Bx = BoundedString.Ex + 1;
                break;

            case RelativePosition.None:
                Bx = -1;
                break;

            default:
                Bx = -1;
                break;
            }

            if (Bx > BoundedString.Ex)
            {
                Bx = -1;
            }

            return(Bx);
        }
Esempio n. 18
0
        // ------------------------ AdvanceNextWord -------------------------
        // Scans to the next word in the string. ( a word being the text bounded by the
        // delimeter and whitespace characters as spcfd in the TextTraits argument )
        // Return null when end of string.
        public static void AdvancexNextWord(
            string InString,
            WordCursor InOutWordCursor,
            TextTraits InTraits)
        {
            int                Bx;
            BoundedString      boundedString = new BoundedString(InString);
            ScanPatternResults spr           = null;

            // calc scan start position
            Bx = ScanWord_CalcStartBx(boundedString, InOutWordCursor);

            // empty the word parts of the cursor.
            InOutWordCursor.EmptyWordParts();

            // advance past whitespace
            if (Bx <= boundedString.Ex)
            {
                Bx = ScanNotEqual(
                    boundedString.String, Bx, boundedString.Ex,
                    InTraits.WhitespacePatterns).FoundPos;
            }

            // got the start of something. scan for the delimeter ( could be the current char )
            spr = null;
            if (Bx <= boundedString.Ex)
            {
                spr = ScanWord_IsolateWord(boundedString, Bx, ref InOutWordCursor, InTraits);
            }

            // depending on the word, isolate and store the delim that follows.
            ScanWord_IsolateDelim(boundedString, spr, ref InOutWordCursor, InTraits);

            // current word position.
            if (InOutWordCursor.ScanEx == -1)
            {
                InOutWordCursor.Position = RelativePosition.End;
            }
            else
            {
                InOutWordCursor.Position = RelativePosition.At;
            }
        }
Esempio n. 19
0
        // --------------------------- ScanCloseQuote ------------------------------
        public static int ScanCloseQuote(
            BoundedString InBounded, int InBx, QuoteEncapsulation InQem)
        {
            char QuoteChar = InBounded.String[InBx];
            int  cloqIx    = -1;

            for (int Ix = InBx + 1; Ix <= InBounded.Ex; ++Ix)
            {
                char ch1 = InBounded.String[Ix];

                // using the escape method to enclose quote chars. This means the escape char
                // is used to encapsulate other special characters in the quoted string.
                // todo: dequote using "QuotedStringTraits" rules.
                if ((ch1 == '\\') &&
                    (InQem == QuoteEncapsulation.Escape) &&
                    (Ix < InBounded.Ex))
                {
                    ++Ix;
                }

                // quote char enquoted using the "double the char" method.
                else if (
                    (ch1 == QuoteChar) &&
                    (InQem == QuoteEncapsulation.Double) &&
                    (Ix < InBounded.Ex) &&
                    (InBounded.String[Ix + 1] == QuoteChar))
                {
                    ++Ix;
                }

                // found the closing quote char.
                else if (ch1 == QuoteChar)
                {
                    cloqIx = Ix;
                    break;
                }
            }

            return(cloqIx);
        }
Esempio n. 20
0
        // ------------------------------ SetDelim ---------------------------------
        public WordCursor SetDelim(
            BoundedString InBoundedString,
            string InDelim, int InDelimBx, DelimClassification InDelimClass)
        {
            mDelim          = InDelim;
            mDelimBx        = InDelimBx;
            this.DelimClass = InDelimClass;

            // check if whitespace after the delim.
            if ((InDelim != null) &&
                (InDelimClass != DelimClassification.Whitespace) &&
                (InDelimClass != DelimClassification.EndOfString))
            {
                int Nx = InDelimBx + InDelim.Length;
                if ((Nx <= InBoundedString.Ex) &&
                    (mTraits.IsWhitespace(InBoundedString, Nx)))
                {
                    mWhitespaceFollowsDelim = true;
                }
            }

            return(this);
        }
Esempio n. 21
0
 /// <summary>
 /// calc if the
 /// </summary>
 /// <param name="InBoundedString"></param>
 /// <param name="InBx"></param>
 /// <returns></returns>
 public bool IsPathPartDelim(BoundedString InBoundedString, int InIx)
 {
     if (InBoundedString.IsOutsideBounds(InIx))
     {
         return(false);
     }
     else if (IsPathSepChar(InBoundedString[InIx]) == false)
     {
         return(false);
     }
     else if (IsWordChar(InBoundedString, InIx - 1) == true)
     {
         return(true);
     }
     else if (IsWordChar(InBoundedString, InIx + 1) == true)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 22
0
        /// <summary>
        /// return the NonWord info of path sep char which is classified as being a
        /// path part delimiter ( it could be a division expression symbol )
        /// </summary>
        /// <param name="InBoundedString"></param>
        /// <param name="InIx"></param>
        /// <returns></returns>
        public ScanPattern GetPathPartDelim(BoundedString InBoundedString, int InIx)
        {
            ScanPattern pat = null;

            if (InBoundedString.IsOutsideBounds(InIx))
            {
            }

            else if (IsPathSepChar(InBoundedString[InIx]) == true)
            {
                pat = NonWordPatterns.FindPatternAtSubstring(
                    InBoundedString.String, InIx, InBoundedString.Ex);

                // the nonword is a path sep char. but is it a pathPart delim?
                // It is if there is a word char before or after the path sep char.
                // ex: /abc/efg vs. a = b / c ;
                if ((IsWordChar(InBoundedString, InIx - 1) == false) &&
                    (IsWordChar(InBoundedString, InIx + 1) == false))
                {
                    pat = null;
                }
            }
            return(pat);
        }
Esempio n. 23
0
 public bool IsWhitespace(
     BoundedString InBoundedString, int InIx)
 {
     return(IsWhitespace(InBoundedString.String, InIx, InBoundedString.Ex));
 }
        // ------------------------ ScanNextWord -------------------------
        // Scans to the next word in the string. ( a word being the text bounded by the
        // delimeter and whitespace characters as spcfd in the TextTraits argument )
        // Return null when end of string.
        public static WordCursor ScanNextWord(
            BoundedString BoundedString,
            WordCursor CurrentWord)
        {
            int                Bx;
            WordCursor         results = null;
            ScanPatternResults spr     = null;

            // stay at the current location.
            if (CurrentWord.StayAtFlag == true)
            {
                if ((CurrentWord.Position != RelativePosition.At) &&
                    (CurrentWord.Position != RelativePosition.End))
                {
                    throw new ApplicationException("cursor not position at location to stay at");
                }
                results            = new WordCursor(CurrentWord);
                results.StayAtFlag = false;
            }

            else
            {
                results = new WordCursor()
                          .SetString(BoundedString.String)
                          .SetTraits(CurrentWord.TextTraits);
                results.VirtualCursor = WordCursor.enumVirtualCursor.None;

                // calc scan start position
                Bx = ScanWord_CalcStartBx(BoundedString, CurrentWord);

                // advance past whitespace
                if ((Bx != -1) && (Bx <= BoundedString.Ex))
                {
                    Bx = ScanNotEqual(
                        BoundedString.String, Bx, BoundedString.Ex,
                        CurrentWord.TextTraits.WhitespacePatterns).FoundPos;
                }

                // got the start of something. scan for the delimeter (could be the current char)
                spr = null;
                DelimClassification sprdc = DelimClassification.None;
                if ((Bx != -1) && (Bx <= BoundedString.Ex))
                {
                    spr =
                        ScanWord_IsolateWord(
                            BoundedString, Bx, ref results, CurrentWord.TextTraits);
                    if (spr.IsNotFound == true)
                    {
                        sprdc = DelimClassification.EndOfString;
                    }
                    else
                    {
                        sprdc = spr.FoundPat.DelimClassification;
                    }
                }

                if (spr == null)
                {
                    results.Position = RelativePosition.End;
                    results.SetDelim(BoundedString, null, -1, DelimClassification.EndOfString);
                }

                else
                {
                    // depending on the word, isolate and store the delim that follows.

                    // OpenNamedBraced. delim is the open brace char.
                    if (results.WordClassification == WordClassification.OpenNamedBraced)
                    {
                        ScanPatternResults spr2;
                        spr2 = ScanEqualAny(
                            BoundedString, Bx, CurrentWord.TextTraits.OpenNamedBracedPatterns);
                        results.SetDelim(
                            BoundedString,
                            spr2.FoundPat.PatternValue,
                            spr2.FoundPos, DelimClassification.OpenNamedBraced);
                    }

                    // OpenContentBraced. word and delim are the same.
                    else if (results.WordClassification == WordClassification.OpenContentBraced)
                    {
                        results.SetDelim(
                            BoundedString,
                            results.Word.Value, results.WordBx, DelimClassification.OpenContentBraced);
                    }

                    // word is CommentToEnd. delim is end of line.
                    else if (results.WordClassification == WordClassification.CommentToEnd)
                    {
                        results.SetDelim(BoundedString, spr, sprdc);
                    }

                    // process the NonWordResults returned by "ScanWord_IsolateWord"
                    else
                    {
                        ScanWord_IsolateDelim(
                            BoundedString, spr, ref results, CurrentWord.TextTraits);
                    }
                }

                // current word position.
                if (results.ScanEx == -1)
                {
                    results.Position = RelativePosition.End;
                    results.SetDelim(BoundedString, null, -1, DelimClassification.EndOfString);
                }
                else
                {
                    results.Position = RelativePosition.At;
                }
            }

            return(results);
        }
        // -------------------- ScanWord_IsolateWord ---------------------------
        // We have a word starting at InBx. Scan to the end of the word.
        // Returns the word in the InOutResults parm.
        // Returns the word delim in the return argument.
        private static ScanPatternResults ScanWord_IsolateWord(
            BoundedString InBoundedString,
            int InBx,
            ref WordCursor InOutResults,
            TextTraits Traits)
        {
            int                Bx, Ix, Lx;
            string             wordText;
            ScanPatternResults spr = null;

            Bx = InBx;
            char ch1 = InBoundedString.String[Bx];

            // is start of a verbatim string literal
            if ((Traits.VerbatimLiteralPattern != null) &&
                (Traits.VerbatimLiteralPattern.Match(InBoundedString, Bx)))
            {
            }

            // is quoted. the word runs to the closing quote.
            else if (IsOpenQuoteChar(ch1) == true)
            {
                Ix = ScanCloseQuote(InBoundedString.String, Bx, Traits.QuoteEncapsulation);
                if ((Ix == -1) || (Ix > InBoundedString.Ex))
                {
                    throw (new ApplicationException(
                               "Closing quote not found starting at position " +
                               Bx.ToString() + " in " + InBoundedString.String));
                }
                Lx       = Ix - Bx + 1;
                wordText = InBoundedString.String.Substring(Bx, Lx);
                InOutResults.SetWord(wordText, WordClassification.Quoted, Bx);

                // setup the non word which follows the closing quote.
                Bx = Ix + 1;
                if (InBoundedString.IsOutsideBounds(Bx))
                {
                    spr = new ScanPatternResults(-1);
                }
                else
                {
                    // the char that follows the closing quote must be a delim
                    spr = ScanEqualAny(InBoundedString, Bx, Traits.NonWordPatterns);
                    if (spr.FoundPos != Bx)
                    {
                        throw new ApplicationException(
                                  "invalid char follows close quote at pos " + Ix.ToString() +
                                  " in " + Stringer.Head(InBoundedString.String, 80));
                    }
                }
            }
            else
            {
                // Scan the string for any of the non word patterns spcfd in Traits.
                DelimClassification sprdc = DelimClassification.None;
                spr = ScanEqualAny(InBoundedString, Bx, Traits.NonWordPatterns);
                if (spr.IsNotFound == false)
                {
                    sprdc = spr.FoundPat.DelimClassification;
                }

                // a quote character within the name.  this is an error.
                if (sprdc == DelimClassification.Quote)
                {
                    throw new ApplicationException(
                              "quote character immed follows name character at position " +
                              spr.FoundPos.ToString() + " in " + InBoundedString.String);
                }

                // no delim found. all word to the end of the string.
                else if (spr.IsNotFound)
                {
                    wordText = InBoundedString.Substring(Bx);
                    InOutResults.SetWord(wordText, WordClassification.Identifier, InBx);
                }

                // found an open named brace char
                else if (sprdc == DelimClassification.OpenNamedBraced)
                {
                    ScanWord_IsolateWord_Braced(
                        InBoundedString, Bx, spr, ref InOutResults, Traits);
                }

                // delim is same position as the word.  so there is no word, only a delim.
                else if (spr.FoundPos == InBx)
                {
                    if (Scanner.IsOpenBraced(sprdc))
                    {
                        InOutResults.SetWord(
                            spr.FoundPat.PatternValue, WordClassification.OpenContentBraced, Bx,
                            spr.FoundPat.LeadChar);
                    }

                    // start of CommentToEnd comment. This is a word, not a delim. Find the
                    // end of the comment and set the delim to that end position.
                    else if (sprdc == DelimClassification.CommentToEnd)
                    {
                        spr = ScanWord_IsolateWord_CommentToEnd(
                            InBoundedString, spr.FoundPos, ref InOutResults, Traits);
                    }

                    else
                    {
                        InOutResults.SetNullWord();
                    }
                }

                // we have a word that ends with a delim.
                else
                {
                    Lx       = spr.FoundPos - InBx;
                    wordText = InBoundedString.Substring(InBx, Lx);
                    InOutResults.SetWord(wordText, WordClassification.Identifier, InBx);
                }
            }

            // return ScanPatternResults of the delim that ends the word.
            return(spr);
        }
        // -------------------- ScanWord_IsolateDelim ---------------------------
        private static void ScanWord_IsolateDelim(
            BoundedString InBoundedString,
            ScanPatternResults InPatternResults,
            ref WordCursor InOutResults,
            TextTraits InTraits)
        {
            // did not find a nonword char.  must have hit end of string.
            if (InPatternResults.IsNotFound)
            {
                InOutResults.DelimClass = DelimClassification.EndOfString;
            }

            // we have a delimiter of some kind.
            else
            {
                DelimClassification sprdc = InPatternResults.FoundPat.DelimClassification;

                InOutResults.WhitespaceFollowsWord  = false;
                InOutResults.WhitespaceFollowsDelim = false;
                InOutResults.DelimIsWhitespace      = false;

                // the delim is a hard delim ( not whitespace )
                if (sprdc != DelimClassification.Whitespace)
                {
                    // Want the openContent brace to be processed as a standalone word. Use
                    // virtual whitespace so the word that this open brace is the delim of will
                    // have what appears to be a whitespace delim. Then the following word will
                    // be the standalone open content brace char.
                    if (sprdc == DelimClassification.OpenContentBraced)
                    {
                        InOutResults.SetDelim(
                            InBoundedString,
                            null, InPatternResults.FoundPos, DelimClassification.VirtualWhitespace);
                    }
                    else
                    {
                        // delim is either as classified in the collection of NonWords or is
                        // a PathPart delim.
                        ScanPattern pat = InTraits.GetPathPartDelim(
                            InBoundedString, InPatternResults.FoundPos);
                        if (pat != null)
                        {
                            InOutResults.SetDelim(
                                InBoundedString,
                                pat.PatternValue,
                                InPatternResults.FoundPos,
                                DelimClassification.PathSep);
                        }
                        else
                        {
                            InOutResults.SetDelim(
                                InBoundedString,
                                InPatternResults.FoundPat.PatternValue,
                                InPatternResults.FoundPos,
                                sprdc);
                        }
                    }
                }

                // whitespace immed follows the word text
                else
                {
                    ScanWord_IsolateDelim_WhitespaceFollows(
                        InBoundedString, InPatternResults, ref InOutResults, InTraits);
                }
            }
        }
        /// <summary>
        /// The delim after the word is whitspace. If what follows the whitespace
        /// is a delim char, then this whitspace is disregarded as the delim, and
        /// the delim is what follows the whitespace.
        /// </summary>
        /// <param name="InBoundedString"></param>
        /// <param name="InNonWordResults"></param>
        /// <param name="InOutResults"></param>
        /// <param name="InTraits"></param>
        private static void ScanWord_IsolateDelim_WhitespaceFollows(
            BoundedString InBoundedString,
            ScanPatternResults InPatternResults,
            ref WordCursor InOutResults,
            TextTraits InTraits)
        {
            InOutResults.WhitespaceFollowsWord = true;
            ScanPattern nwPat = null;

            // Look for hard delim after the ws.
            ScanPatternResults scanResults =
                ScanNotEqual(
                    InBoundedString.String, InPatternResults.FoundPos,
                    InBoundedString.Ex, InTraits.WhitespacePatterns);

            // look that the char after the ws is a nonword.
            if (scanResults.FoundPos != -1)
            {
                nwPat = InTraits.NonWordPatterns.FindPatternAtSubstring(
                    InBoundedString, scanResults.FoundPos);
            }

            // the char after the whitespace is a non word (delim) char.
            if (nwPat != null)
            {
                DelimClassification nwdc = nwPat.DelimClassification;

                // is the delim actually a sep char in a path name.
                // so the delim is the whitespace.
                if (InTraits.IsPathPartDelim(InBoundedString, scanResults.FoundPos))
                {
                    ScanWord_IsolateDelim_SetDelimIsWhitespace(
                        InBoundedString, InTraits, InOutResults, InPatternResults.FoundPos);
                }

                // is a content open brace char. delim stays as whitespace because
                // content braces are considered standalone words.
                else if (nwPat.DelimClassification.IsOpenBraced( ))
                {
                    ScanWord_IsolateDelim_SetDelimIsWhitespace(
                        InBoundedString, InTraits, InOutResults, InPatternResults.FoundPos);
                }

                // is a quote char. the quoted string is considered a word.
                else if (nwdc == DelimClassification.Quote)
                {
                    ScanWord_IsolateDelim_SetDelimIsWhitespace(
                        InBoundedString, InTraits, InOutResults, InPatternResults.FoundPos);
                }

                // is an actual delim.
                else
                {
                    InOutResults.SetDelim(
                        InBoundedString,
                        nwPat.PatternValue, scanResults.FoundPos, nwdc);
                }
            }

            // the whitespace char is the delim of record.
            else
            {
                ScanWord_IsolateDelim_SetDelimIsWhitespace(
                    InBoundedString, InTraits, InOutResults, InPatternResults.FoundPos);
            }
        }