/// <summary>
        /// Examine the string for its WordClassification content.
        /// </summary>
        /// <param name="InWord"></param>
        /// <param name="InTraits"></param>
        /// <returns></returns>
        public static CharObjectPair CalcWordClassification(
            string InWord, TextTraits InTraits)
        {
            int Fx = 0, Ix = 0;
            WordClassification wc = WordClassification.None;
            char braceChar        = ' ';
            char ch1              = AcCommon.PullChar(InWord, 0);
            int  Ex               = InWord.Length - 1;

            // is quoted. the word runs to the closing quote.
            if (Scanner.IsOpenQuoteChar(ch1) == true)
            {
                Ix = Scanner.ScanCloseQuote(InWord, 0, InTraits.QuoteEncapsulation);
                if (Ix == Ex)
                {
                    wc = WordClassification.Quoted;
                }
                else
                {
                    wc = WordClassification.MixedText;
                }
            }

            // check if the string is a Braced or NameBraced word.
            if (wc == WordClassification.None)
            {
                char[] combo = AcCommon.Concat(InTraits.DelimChars, InTraits.BraceChars);
                Scanner.ScanCharResults results = Scanner.ScanEqual(InWord, 0, combo);
                Fx  = results.ResultPos;
                ch1 = results.ResultChar;

                // found a brace char
                if ((InTraits.IsOpenBraceChar(ch1) == true) &&
                    (InTraits.IsDelimChar(ch1) == false))
                {
                    Ix = Scanner.ScanCloseBrace(InWord, Fx);
                    if (Ix == Ex)
                    {
                        braceChar = ch1;
                        if (Fx == 0)
                        {
                            wc = WordClassification.Braced;
                        }
                        else
                        {
                            wc = WordClassification.NameBraced;
                        }
                    }
                }
            }

            // word is all delimeter.
            if (wc == WordClassification.None)
            {
                Fx = Scanner.ScanNotEqual(InWord, 0, InTraits.DelimChars).a;
                if (Fx >= 0)
                {
                    wc = WordClassification.Delimeter;
                }
            }

            // check if a numeric string.
            if (wc == WordClassification.None)
            {
                char[] digitChars =
                    new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '+', '-' };
                Fx = Scanner.ScanNotEqual(InWord, 0, digitChars).a;
                if (Fx == -1)
                {
                    wc = WordClassification.Numeric;
                    try
                    {
                        double vx = double.Parse(InWord);
                    }
                    catch (Exception)
                    {
                        wc = WordClassification.None;
                    }
                }
            }

            // any delim chars in the string.  if not, the string is a name.  otherwise, it is
            // mixed.
            if (wc == WordClassification.None)
            {
                Fx = Scanner.ScanEqual(InWord, 0, InTraits.DelimChars).a;
                if (Fx == -1)
                {
                    wc = WordClassification.Name;
                }
                else
                {
                    wc = WordClassification.MixedText;
                }
            }

            return(new CharObjectPair(braceChar, wc));
        }
Exemple #2
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);
            }
        }
 /// <summary>
 /// standard set of delimeter characters.
 /// </summary>
 /// <returns></returns>
 public static char[] StandardDelimChars( )
 {
     char[] ch3 = new char[] { ' ', '\t', ',' };
     return(AcCommon.Concat(ch3, StandardBraceChars( )));
 }