Пример #1
0
        /// <summary>
        /// This is used to get a classifier based on the script language
        /// </summary>
        /// <param name="language">The script language</param>
        /// <returns>A classifier based on the script language</returns>
        private TextClassifier GetClassifier(string language)
        {
            // Cache the script classifiers as there may be more than one script block on the page
            if (!classifiers.TryGetValue(language ?? String.Empty, out TextClassifier c))
            {
                if (!String.IsNullOrWhiteSpace(language) &&
                    language.IndexOf("vb", StringComparison.OrdinalIgnoreCase) != -1)
                {
                    c = ClassifierFactory.GetClassifier("~~.vb", this.SpellCheckConfiguration);
                }
                else
                if (!String.IsNullOrWhiteSpace(language) &&
                    (language.IndexOf("JavaScript", StringComparison.OrdinalIgnoreCase) != -1 ||
                     language.IndexOf("TypeScript", StringComparison.OrdinalIgnoreCase) != -1))
                {
                    c = ClassifierFactory.GetClassifier("~~.js", this.SpellCheckConfiguration);
                }
                else
                {
                    // Anything else is considered a C-style script language (C#, PHP, etc.).
                    c = ClassifierFactory.GetClassifier("~~.cs", this.SpellCheckConfiguration);
                }

                classifiers.Add(language ?? String.Empty, c);
            }

            return(c);
        }
Пример #2
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="filename">The filename to load</param>
        /// <param name="spellCheckConfiguration">The spell checker configuration for the file</param>
        /// <param name="classifierConfiguration">The configuration element containing the classification
        /// expressions and their range types.</param>
        public CodeClassifier(string filename, SpellCheckerConfiguration spellCheckConfiguration,
                              XElement classifierConfiguration) : base(filename, spellCheckConfiguration, classifierConfiguration)
        {
            xmlDocCommentDelimiter      = (string)classifierConfiguration.Attribute("XmlDocCommentDelimiter");
            quadSlashDelimiter          = (string)classifierConfiguration.Attribute("QuadSlashDelimiter");
            oldStyleDocCommentDelimiter = (string)classifierConfiguration.Attribute("OldStyleDocCommentDelimiter");

            isCSharp     = filename.EndsWith(".cs", StringComparison.OrdinalIgnoreCase);
            isCStyleCode = (spellCheckConfiguration.CSharpOptions.ApplyToAllCStyleLanguages &&
                            ClassifierFactory.IsCStyleCode(filename));
        }
Пример #3
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="filename">The filename to load</param>
        /// <param name="spellCheckConfiguration">The spell checker configuration for the file</param>
        protected TextClassifier(string filename, SpellCheckerConfiguration spellCheckConfiguration)
        {
            this.Filename = filename;
            this.SpellCheckConfiguration = spellCheckConfiguration;

            ignoredClassifications = new List <RangeClassification>();

            // Get the ignored classifications based on the extension.  If there are none, check for the
            // file type.
            string ext = Path.GetExtension(filename);

            if (!String.IsNullOrWhiteSpace(ext))
            {
                ext = ext.Substring(1);
            }

            var exclusions = spellCheckConfiguration.IgnoredClassificationsFor(PropertyNames.Extension + ext);

            if (!exclusions.Any())
            {
                exclusions = spellCheckConfiguration.IgnoredClassificationsFor(PropertyNames.FileType +
                                                                               ClassifierFactory.ClassifierIdFor(filename));
            }

            RangeClassification rangeType;

            foreach (string exclusion in exclusions)
            {
                if (Enum.TryParse <RangeClassification>(exclusion, out rangeType))
                {
                    ignoredClassifications.Add(rangeType);
                }
            }

            if (!File.Exists(filename))
            {
                this.SetText(String.Empty);
            }
            else
            {
                using (StreamReader sr = new StreamReader(filename, Encoding.Default, true))
                {
                    this.SetText(sr.ReadToEnd());
                }
            }
        }