Esempio n. 1
0
        /// <summary>
        /// Extracts comments
        /// </summary>
        /// <param name="text">Text to perform extract on</param>
        /// <returns>List of comments</returns>
        public virtual IEnumerable <string> ExtractComments(string text)
        {
            MatchCollection matches = CommentsAndStringLiteralsRegexStringRegex.Matches(text);

            foreach (Match match in matches)
            {
                if (match.Groups[RegularExpressions.GroupInlineCommentName].Value != "")
                {
                    foreach (string commentWord in SplitOnWhiteSpaceRegex.Split(match.Groups[RegularExpressions.GroupInlineCommentName].Value))
                    {
                        if (commentWord != "")
                        {
                            yield return(commentWord);
                        }
                    }
                }

                if (match.Groups[RegularExpressions.GroupMultilineCommentName].Value != "")
                {
                    foreach (string commentWord in SplitOnWhiteSpaceRegex.Split(match.Groups[RegularExpressions.GroupMultilineCommentName].Value))
                    {
                        if (commentWord != "")
                        {
                            yield return(commentWord);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Extracts string literals
        /// </summary>
        /// <param name="text">Text to perform extract on</param>
        /// <returns>List of string literals</returns>
        public virtual IEnumerable <string> ExtractStringLiterals(string text)
        {
            MatchCollection matches = CommentsAndStringLiteralsRegexStringRegex.Matches(text);

            foreach (string stringLiterals in (from Match match in matches
                                               where match.Groups[RegularExpressions.GroupStringLiteralsName].Value != ""
                                               select match.Groups[RegularExpressions.GroupStringLiteralsName].Value))
            {
                foreach (string stringLiteralWord in SplitOnWhiteSpaceRegex.Split(stringLiterals))
                {
                    if (stringLiteralWord != "")
                    {
                        yield return(stringLiteralWord);
                    }
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Removes comments and string literals
 /// </summary>
 /// <param name="text">Text to remove comments and string literals</param>
 /// <remarks>It is necessary to replace them with space. Eg: static/*hello*/void is acceptable.</remarks>
 /// <returns>Text without any comments and string literals</returns>
 public string RemoveCommentsAndStringLiterals(string text)
 {
     text = CommentsAndStringLiteralsRegexStringRegex.Replace(text, RegularExpressions.Space);
     return(text);
 }