Exemple #1
0
        /// <summary>
        /// Scan for keyword followed by enclosign parenthesis.
        /// Return the string within the encoding paren.
        /// Return null if keyword is not found.
        /// </summary>
        /// <param name="InText"></param>
        /// <param name="InKwd"></param>
        /// <returns></returns>
        public static string ScanParenEnclosedValue(this string InText, string InKwd)
        {
            string foundValue = null;
            string findText   = InKwd + "(";
            int    fx         = InText.IndexOf(findText);

            if (fx >= 0)
            {
                int braceBx = fx + InKwd.Length;
                int ex      = Scanner.ScanCloseBrace(InText, braceBx);
                if (ex >= 0)
                {
                    int valueBx = braceBx + 1;
                    int valueLx = ex - valueBx;
                    if (valueLx > 0)
                    {
                        foundValue = InText.Substring(valueBx, valueLx).Trim();
                    }
                    else
                    {
                        foundValue = "";
                    }
                }
            }

            return(foundValue);
        }
        /// <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));
        }