Ejemplo n.º 1
0
        /// <summary>
        /// Extracts everyting: String literals, method names and identifier names
        /// </summary>
        /// <param name="text">Text to extract from</param>
        /// <returns>List of identifiers</returns>
        public virtual IEnumerable <string> ExtractIdentifiersAndStringLiterals(string text)
        {
            // Step 1 : Remove package declaration
            text = RemovePackageDeclarationAndImports(text);

            // Step 2: remove keywords
            text = RemoveKeywords(text);

            // Step 3: Extract String Literals
            foreach (string item in ExtractStringLiterals(text))
            {
                yield return(item);
            }

            // Step 4: Remove comments and string literals
            text = RemoveCommentsAndStringLiterals(text);

            // Step 5: now everything is plain source code. remove annotations
            text = RemoveAnnotations(text);

            // Step 6: remove generic type parameter
            text = RemoveGenericTypeParameters(text);

            // Step 7: Replace all white space by single
            text = WhiteSpaceRegex.Replace(text, RegularExpressions.Space);

            MatchCollection      methodMatches    = MethodDeclarationRegexStringRegex.Matches(text);
            IEnumerable <string> methodEnumerable = (from Match match in methodMatches
                                                     where match.Groups[1].Value != ""
                                                     select match.Groups[1].Value);

            foreach (string item in methodEnumerable)
            {
                yield return(item);
            }

            MatchCollection variableMatches = VariableDeclarationRegexStringRegex.Matches(text);

            foreach (Match match in variableMatches)
            {
                int group = 1;
                while (match.Groups[group].Value != "")
                {
                    IEnumerable <string> variableEnumerable = (from Capture capture in match.Groups[@group].Captures select capture.Value);
                    foreach (string item in variableEnumerable)
                    {
                        yield return(item);
                    }
                    group++;
                }
            }
        }
 private static bool LooksLikeSql(string str)
 {
     return(WhiteSpaceRegex.Matches(str)
            .Cast <Match>()
            .Any(w => SqlKeyWords.Contains(w.Value)));
 }
Ejemplo n.º 3
0
 public static string WithoutWhitespace(this string input)
 {
     return(WhiteSpaceRegex.Replace(input, string.Empty));
 }