Пример #1
0
 /// <summary>
 /// Return the file name stripped of the extension part.
 /// </summary>
 /// <param name="InFileName"></param>
 /// <returns></returns>
 public static string NameSansExtension(string InFileName)
 {
     Scanner.ScanCharResults rv =
         Scanner.ScanReverseEqual(InFileName, '.');
     if (rv.ResultPos < 0)
     {
         return(InFileName);
     }
     else if (rv.ResultPos == 0)
     {
         return("");
     }
     else
     {
         return(InFileName.Substring(0, rv.ResultPos));
     }
 }
Пример #2
0
        /// <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));
        }