コード例 #1
0
ファイル: WordParser.cs プロジェクト: wapagit/StyleCop
        internal static Collection <string> Parse(string text, WordParserOptions options, char prefix)
        {
            string              str;
            WordParser          parser     = new WordParser(text, options, prefix);
            Collection <string> collection = new Collection <string>();

            while ((str = parser.NextWord()) != null)
            {
                collection.Add(str);
            }

            return(collection);
        }
コード例 #2
0
ファイル: WordParser.cs プロジェクト: wapagit/StyleCop
        internal static bool ContainsWord(string text, WordParserOptions options, char prefix, params string[] words)
        {
            string str;

            if (words == null)
            {
                throw new ArgumentNullException("words");
            }

            WordParser parser = new WordParser(text, options, prefix);

            while ((str = parser.NextWord()) != null)
            {
                foreach (string str2 in words)
                {
                    if (string.Equals(str, str2, StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #3
0
ファイル: WordParser.cs プロジェクト: kopelli/Visual-StyleCop
        internal static Collection<string> Parse(string text, WordParserOptions options, char prefix)
        {
            string str;
            WordParser parser = new WordParser(text, options, prefix);
            Collection<string> collection = new Collection<string>();
            while ((str = parser.NextWord()) != null)
            {
                collection.Add(str);
            }

            return collection;
        }
コード例 #4
0
ファイル: WordParser.cs プロジェクト: kopelli/Visual-StyleCop
        internal static bool ContainsWord(string text, WordParserOptions options, char prefix, params string[] words)
        {
            string str;
            if (words == null)
            {
                throw new ArgumentNullException("words");
            }

            WordParser parser = new WordParser(text, options, prefix);
            while ((str = parser.NextWord()) != null)
            {
                foreach (string str2 in words)
                {
                    if (string.Equals(str, str2, StringComparison.OrdinalIgnoreCase))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
コード例 #5
0
        /// <summary>
        /// Spell check.
        /// </summary>
        /// <param name='element'>
        /// Element in the document.
        /// </param>
        /// <param name='lineNumber'>
        /// Line number.
        /// </param>
        /// <param name='document'>
        /// Document XML.
        /// </param>
        /// <param name='type'>
        /// Type of the XML node
        /// </param>
        private void SpellCheck(CsElement element, int lineNumber, XmlNode document, string type)
        {
            this.WriteMessage("Spell check");
            this.WriteMessage(lineNumber.ToString());
            this.WriteMessage(type);
            if (this.speller != null)
            {
                this.WriteMessage("Spell checker available");
                if (document != null && !string.IsNullOrEmpty(document.InnerText))
                {
                    this.WriteMessage("Document available");
                    WordParser parser = new WordParser(document.InnerText, WordParserOptions.SplitCompoundWords);
                    this.WriteMessage("Document parsed");
                    if (parser.PeekWord() != null)
                    {
                        this.WriteMessage("Parser has found a word");
                        var recognizedWords = element.Document.SourceCode.Project.RecognizedWords;
                        this.WriteMessage("Found recognized words");
                        string word = parser.NextWord();
                        this.WriteMessage(word);
                        do
                        {
                            this.WriteMessage(word);
                            if ((!word.StartsWith("$") || !word.EndsWith("$")) && (!recognizedWords.Contains(word) && !this.speller.Spell(word)))
                            {
                                this.WriteMessage("Violation found");
                                this.AddViolation(element, lineNumber, "CommentSpellingIncorrect", word, type);
                                this.WriteMessage("Violation added");
                            }
                        }
                        while ((word = parser.NextWord()) != null);
                        this.WriteMessage("Done parsing");
                    }
                }
            }

            this.WriteMessage("Spell check call completed");
        }
コード例 #6
0
        /// <summary>
        /// Returns True if the text has incorrect spelling.
        /// </summary>
        /// <param name="element">
        /// The element containing the text we're checking.
        /// </param>
        /// <param name="text">
        /// The text to check.
        /// </param>
        /// <param name="spellingError">
        /// Returns a comma separated list of words encountered as spelling errors.
        /// </param>
        /// <returns>
        /// True if the text contains an incorrect spelling.
        /// </returns>
        private static bool TextContainsIncorectSpelling(CsElement element, string text, out string spellingError)
        {
            NamingService namingService = NamingService.GetNamingService(element.Document.SourceCode.Project.Culture);

            spellingError = string.Empty;

            if (namingService.SupportsSpelling)
            {
                ICollection<string> recognizedWords = element.Document.SourceCode.Project.RecognizedWords;

                WordParser parser = new WordParser(text, WordParserOptions.SplitCompoundWords, recognizedWords);
                if (parser.PeekWord() != null)
                {
                    string word = parser.NextWord();
                    do
                    {
                        // Ignore words starting and ending with '$'.
                        // Ignore if in our recognized words list or correct spelling
                        if ((word.StartsWith("$") && word.EndsWith("$")) || (recognizedWords.Contains(word) || IsSpelledCorrectly(namingService, word)))
                        {
                            continue;
                        }

                        if (!string.IsNullOrEmpty(spellingError))
                        {
                            spellingError += ", ";
                        }

                        spellingError += word;
                    }
                    while ((word = parser.NextWord()) != null);
                }
            }

            return !string.IsNullOrEmpty(spellingError);
        }