示例#1
0
        public Counter(string inputFile, string[] configuration)
        {
            this.inputFile = inputFile;

            foreach (string c in configuration)
            {
                string[] parts = c.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length != 1 && parts.Length != 2 && parts.Length != 4)
                {
                    Warnings.Add("Invalid configuration line: " + c);
                    continue;
                }

                string extension = "." + parts[0].ToLower();
                fileTypes.Add(extension);

                if (parts.Length > 1)
                {
                    if (parts[1].ToLower() == "default")
                    {
                        profiles.Add(extension, CommentProfile.Default);
                    }
                    else
                    {
                        CommentProfile profile = new CommentProfile();
                        profile.LineComment = parts[1];

                        if (parts.Length > 2)
                        {
                            profile.StartComment = parts[2];
                            profile.EndComment   = parts[3];
                        }

                        profiles.Add(extension, profile);
                    }
                }
                else
                {
                    profiles.Add(extension, CommentProfile.Empty);
                }
            }
        }
示例#2
0
        internal void CountFile(FileNode file)
        {
            string extension = Path.GetExtension(file.Path).ToLower();

            if (!fileTypes.Contains(extension))
            {
                file.Valid = false;
                return;
            }

            if (!File.Exists(file.Path))
            {
                throw new InvalidOperationException("Could not open file " + file.Path);
            }

            file.Valid = true;
            file.Name  = Path.GetFileName(file.Path);

            string[] lines     = File.ReadAllLines(file.Path);
            bool     inComment = false;

            CommentProfile profile = CommentProfile.Empty;

            if (profiles.ContainsKey(extension))
            {
                profile = profiles[extension];
            }

            foreach (string line in lines)
            {
                file.TotalLines++;

                string temp = line.Trim();

                if (string.IsNullOrEmpty(temp))
                {
                    file.BlankLines++;
                }
                else if (inComment)
                {
                    file.Comments++;

                    if (temp.Contains(profile.EndComment))
                    {
                        inComment = false;
                    }
                }
                else
                {
                    if (profile.LineComment != null && temp.StartsWith(profile.LineComment))
                    {
                        file.Comments++;
                    }
                    else if (profile.StartComment != null && temp.Contains(profile.StartComment))
                    {
                        file.Comments++;
                        inComment = true;
                    }
                    else
                    {
                        file.CodeLines++;
                    }
                }
            }
        }
示例#3
0
文件: Counter.cs 项目: zhandb/slimdx
        public Counter(string inputFile, string[] configuration)
        {
            this.inputFile = inputFile;

            foreach (string c in configuration)
            {
                string[] parts = c.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length != 1 && parts.Length != 2 && parts.Length != 4)
                {
                    Warnings.Add("Invalid configuration line: " + c);
                    continue;
                }

                string extension = "." + parts[0].ToLower();
                fileTypes.Add(extension);

                if (parts.Length > 1)
                {
                    if (parts[1].ToLower() == "default")
                        profiles.Add(extension, CommentProfile.Default);
                    else
                    {
                        CommentProfile profile = new CommentProfile();
                        profile.LineComment = parts[1];

                        if (parts.Length > 2)
                        {
                            profile.StartComment = parts[2];
                            profile.EndComment = parts[3];
                        }

                        profiles.Add(extension, profile);
                    }
                }
                else
                    profiles.Add(extension, CommentProfile.Empty);
            }
        }