public static void Init() { CountLines window = GetWindow <CountLines>("Count Lines"); window.Show(); window.Focus(); window.DoCountLines(); }
public void Count_lineTest() { string text = "If you're going to try, go all the way. Otherwise, don't even start."; CountLines lines = new CountLines(text); int count = 1; Assert.IsTrue(count == lines.Count_line()); //Assert.Fail(); }
/// <summary> /// 进行各种统计的函数 /// </summary> /// <param name="s"></param> static void Operate(string s) { CountCharacters count_characters = new CountCharacters(s); count_characters.Count_character(); CountLines count_lines = new CountLines(s); count_lines.Count_line(); CountWords count_words = new CountWords(s); count_words.Count_word(); count_words.Count_word_frequency(); }
public static string ExecXYZ(string filepath, string separator = " ", string pathaddition = "some") { string filename = Filename.FromFullPath(filepath); string filedir = Filename.FolderFromFullPath(filepath); string new_name = Path.Combine(filedir, pathaddition + filename).Replace(".txt", ".pcd"); StreamWriter output = new StreamWriter(new_name); output.Write(string.Format(header, CountLines.CountLinesReader(new FileInfo(filepath)))); using (var input = new StreamReader(filepath)) { string input_line = ""; while ((input_line = input.ReadLine()) != null) { if (input_line.Contains("# .PCD v.7 - Point Cloud Data file format")) { return(""); } string[] parts = input_line.Split(separator); double x = double.Parse(parts[0]); double y = double.Parse(parts[1]); double z = double.Parse(parts[2]); input_line = string.Format("{0:F5} {1:F5} {2:F5}", x, y, z); output.WriteLine(input_line); } input.Close(); } output.Close(); return(new_name); /*string[] lines = File.ReadAllLines(filepath); * * if (lines[0].Contains("# .PCD v.7 - Point Cloud Data file format")) { * return ""; // the file has already been processed * } * * for (int i = 0; i < lines.Length; i++) { * string[] parts = lines[i].Split(separator); * double x = double.Parse(parts[0]); * double y = double.Parse(parts[1]); * double z = double.Parse(parts[2]); * // double colour = threeValRgbToOneVal(parts[3], parts[4], parts[5]); * lines[i] = string.Format("{0:F5} {1:F5} {2:F5}", x,y,z); * } * File.WriteAllText(filepath.Replace(".txt", ".pcd"), string.Format(header, lines.Length, string.Join("\n", lines))); * return filepath.Replace(".txt", ".pcd");*/ }
private ToolStripMenuItem CreateCountLinesMenuItem(ToolStripMenuItem toolStripMenuItem, string clickedItemPath, ShellExtInitServer shellServer) { if ("Text" == new FileTypes().GetFileType(Path.GetExtension(clickedItemPath))) { return(toolStripMenuItem); } var countLines = new CountLines(); var countLinesMenuItem = countLines.CreateToolStripMenuItem(shellServer.SelectedItemPaths); toolStripMenuItem.DropDownItems.Add(countLinesMenuItem); var countCleanLinesMenuItem = countLines.CreateToolStripMenuItem(shellServer.SelectedItemPaths, true); toolStripMenuItem.DropDownItems.Add(countCleanLinesMenuItem); return(toolStripMenuItem); }
/// <summary> /// Performs a complete counting and summation of all lines /// in all projects and files. /// </summary> private void SumSolution() { try { // Clean the list lvSummary.Items.Clear(); lvFileList.Items.Clear(); lvFileList.Groups.Clear(); // Configure progress bars tsprgTotal.Minimum = 0; tsprgTotal.Step = 1; tsprgTask.Minimum = 0; tsprgTask.Step = 1; // Skip if there are no projects if (m_summaryList == null || (m_summaryList != null && m_summaryList.Count == 1)) { MessageBox.Show("There are no projects loaded to summarize.", "Line Counter"); return; } // Get all projects summary LineCountSummary allProjects = m_summaryList[0]; allProjects.LineCountSummaryDetails.Reset(); AddSummaryListItem(allProjects, lvSummary.Groups["lvgAllProj"]); tsprgTotal.Maximum = m_summaryList.Count; tsprgTotal.Value = 0; for (int s = 1; s < m_summaryList.Count; s++) { tsprgTotal.PerformStep(); LineCountSummary summary = m_summaryList[s]; summary.LineCountSummaryDetails.Reset(); AddSummaryListItem(summary, lvSummary.Groups["lvgEachProj"]); tsprgTask.Maximum = summary.FileLineCountInfo.Count; tsprgTask.Value = 0; for (int i = 0; i < summary.FileLineCountInfo.Count; i++) { tsprgTask.PerformStep(); LineCountInfo info = summary.FileLineCountInfo[i]; if (m_countableTypes.Contains(info.FileType)) { info.LineCountInfoDetails.Reset(); #if IMPR2 foreach (CountingAlgorithmDescriptor desc in countingAlgorithms) { if (desc.CanCountLines(info)) { desc.GetAlgorithm().CountLines(info); break; } } #else try { CountLines counter = m_countAlgorithms[info.FileType]; counter(info); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } #endif info.LineCountInfoDetails.Summarize(); allProjects.LineCountSummaryDetails.Add(info.LineCountInfoDetails); summary.LineCountSummaryDetails.Add(info.LineCountInfoDetails); tstxtLinesCounted.Text = allProjects.LineCountSummaryDetails.TotalLines.ToString(); AddFileListItem(info); } } summary.LineCountSummaryDetails.Summarize(); LineCountDetails details = summary.LineCountSummaryDetails; summary.LinkedListViewItem.SubItems[1].Text = details.TotalLines.ToString(); summary.LinkedListViewItem.SubItems[2].Text = details.CodeLines.ToString(); summary.LinkedListViewItem.SubItems[3].Text = details.CommentLines.ToString(); summary.LinkedListViewItem.SubItems[4].Text = details.BlankLines.ToString(); summary.LinkedListViewItem.SubItems[5].Text = details.NetLines.ToString(); details = null; } allProjects.LineCountSummaryDetails.Summarize(); LineCountDetails totals = allProjects.LineCountSummaryDetails; allProjects.LinkedListViewItem.SubItems[1].Text = totals.TotalLines.ToString(); allProjects.LinkedListViewItem.SubItems[2].Text = totals.CodeLines.ToString(); allProjects.LinkedListViewItem.SubItems[3].Text = totals.CommentLines.ToString(); allProjects.LinkedListViewItem.SubItems[4].Text = totals.BlankLines.ToString(); allProjects.LinkedListViewItem.SubItems[5].Text = totals.NetLines.ToString(); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } tsprgTotal.Value = tsprgTotal.Maximum; }
/// <summary> /// Construct the line counter user interface and /// the countable file type mappings (to icons and /// counting algorithms). /// </summary> public LineCounterBrowser() { InitializeComponent(); #if IMPR1 projectImageListHelper = new ImageListHelper(imgProjectTypes); fileImageListHelper = new ImageListHelper(imgFileTypes); #endif // Map project types to icons for use in the projects list m_projIconMappings = new Dictionary <string, int>(); m_projIconMappings.Add("{00000000-0000-0000-0000-000000000000}", 0); m_projIconMappings.Add("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", 1); // C# m_projIconMappings.Add("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", 2); // VB m_projIconMappings.Add("{00000001-0000-0000-0000-000000000000}", 5); // List all the countable file types (so we don't try to count .dll's, // images, executables, etc. m_countableTypes = new System.Collections.Specialized.StringCollection(); #if IMPR2 countingAlgorithms = AddInTree.BuildItems <CountingAlgorithmDescriptor> ("/AddIns/LineCounter/CountingAlgorithms", this); // Iterate through algorithms to fill list of known countable types foreach (CountingAlgorithmDescriptor desc in countingAlgorithms) { m_countableTypes.AddRange(desc.extensions); } #else m_countableTypes.Add("*"); m_countableTypes.Add(".cs"); m_countableTypes.Add(".vb"); m_countableTypes.Add(".vj"); m_countableTypes.Add(".cpp"); m_countableTypes.Add(".cc"); m_countableTypes.Add(".cxx"); m_countableTypes.Add(".c"); m_countableTypes.Add(".hpp"); m_countableTypes.Add(".hh"); m_countableTypes.Add(".hxx"); m_countableTypes.Add(".h"); m_countableTypes.Add(".js"); m_countableTypes.Add(".cd"); m_countableTypes.Add(".resx"); m_countableTypes.Add(".res"); m_countableTypes.Add(".css"); m_countableTypes.Add(".htm"); m_countableTypes.Add(".html"); m_countableTypes.Add(".xml"); m_countableTypes.Add(".xsl"); m_countableTypes.Add(".xslt"); m_countableTypes.Add(".xsd"); m_countableTypes.Add(".config"); m_countableTypes.Add(".asax"); m_countableTypes.Add(".ascx"); m_countableTypes.Add(".asmx"); m_countableTypes.Add(".aspx"); m_countableTypes.Add(".ashx"); m_countableTypes.Add(".idl"); m_countableTypes.Add(".odl"); m_countableTypes.Add(".txt"); m_countableTypes.Add(".sql"); #endif // Map file extensions to icons for use in the file list m_fileIconMappings = new Dictionary <string, int>(33); m_fileIconMappings.Add("*", 0); m_fileIconMappings.Add(".cs", 1); m_fileIconMappings.Add(".vb", 2); m_fileIconMappings.Add(".vj", 3); m_fileIconMappings.Add(".cpp", 4); m_fileIconMappings.Add(".cc", 4); m_fileIconMappings.Add(".cxx", 4); m_fileIconMappings.Add(".c", 5); m_fileIconMappings.Add(".hpp", 6); m_fileIconMappings.Add(".hh", 6); m_fileIconMappings.Add(".hxx", 6); m_fileIconMappings.Add(".h", 6); m_fileIconMappings.Add(".js", 7); m_fileIconMappings.Add(".cd", 8); m_fileIconMappings.Add(".resx", 9); m_fileIconMappings.Add(".res", 9); m_fileIconMappings.Add(".css", 10); m_fileIconMappings.Add(".htm", 11); m_fileIconMappings.Add(".html", 11); m_fileIconMappings.Add(".xml", 12); m_fileIconMappings.Add(".xsl", 13); m_fileIconMappings.Add(".xslt", 13); m_fileIconMappings.Add(".xsd", 14); m_fileIconMappings.Add(".config", 15); m_fileIconMappings.Add(".asax", 16); m_fileIconMappings.Add(".ascx", 17); m_fileIconMappings.Add(".asmx", 18); m_fileIconMappings.Add(".aspx", 19); m_fileIconMappings.Add(".ashx", 0); m_fileIconMappings.Add(".idl", 0); m_fileIconMappings.Add(".odl", 0); m_fileIconMappings.Add(".txt", 0); m_fileIconMappings.Add(".sql", 0); // Prepare counting algorithm mappings CountLines countLinesGeneric = new CountLines(CountLinesGeneric); CountLines countLinesCStyle = new CountLines(CountLinesCStyle); CountLines countLinesVBStyle = new CountLines(CountLinesVBStyle); CountLines countLinesXMLStyle = new CountLines(CountLinesXMLStyle); m_countAlgorithms = new Dictionary <string, CountLines>(33); m_countAlgorithms.Add("*", countLinesGeneric); m_countAlgorithms.Add(".cs", countLinesCStyle); m_countAlgorithms.Add(".vb", countLinesVBStyle); m_countAlgorithms.Add(".vj", countLinesCStyle); m_countAlgorithms.Add(".js", countLinesCStyle); m_countAlgorithms.Add(".cpp", countLinesCStyle); m_countAlgorithms.Add(".cc", countLinesCStyle); m_countAlgorithms.Add(".cxx", countLinesCStyle); m_countAlgorithms.Add(".c", countLinesCStyle); m_countAlgorithms.Add(".hpp", countLinesCStyle); m_countAlgorithms.Add(".hh", countLinesCStyle); m_countAlgorithms.Add(".hxx", countLinesCStyle); m_countAlgorithms.Add(".h", countLinesCStyle); m_countAlgorithms.Add(".idl", countLinesCStyle); m_countAlgorithms.Add(".odl", countLinesCStyle); m_countAlgorithms.Add(".txt", countLinesGeneric); m_countAlgorithms.Add(".xml", countLinesXMLStyle); m_countAlgorithms.Add(".xsl", countLinesXMLStyle); m_countAlgorithms.Add(".xslt", countLinesXMLStyle); m_countAlgorithms.Add(".xsd", countLinesXMLStyle); m_countAlgorithms.Add(".config", countLinesXMLStyle); m_countAlgorithms.Add(".res", countLinesGeneric); m_countAlgorithms.Add(".resx", countLinesXMLStyle); m_countAlgorithms.Add(".aspx", countLinesXMLStyle); m_countAlgorithms.Add(".ascx", countLinesXMLStyle); m_countAlgorithms.Add(".ashx", countLinesXMLStyle); m_countAlgorithms.Add(".asmx", countLinesXMLStyle); m_countAlgorithms.Add(".asax", countLinesXMLStyle); m_countAlgorithms.Add(".htm", countLinesXMLStyle); m_countAlgorithms.Add(".html", countLinesXMLStyle); m_countAlgorithms.Add(".css", countLinesCStyle); m_countAlgorithms.Add(".sql", countLinesGeneric); m_countAlgorithms.Add(".cd", countLinesGeneric); }
/// <summary> /// Construct the line counter user interface and /// the countable file type mappings (to icons and /// counting algorithms). /// </summary> public LineCounterBrowser() { InitializeComponent(); #if IMPR1 projectImageListHelper = new ImageListHelper(imgProjectTypes); fileImageListHelper = new ImageListHelper(imgFileTypes); #endif // Map project types to icons for use in the projects list m_projIconMappings = new Dictionary<string, int>(); m_projIconMappings.Add("{00000000-0000-0000-0000-000000000000}", 0); m_projIconMappings.Add("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", 1); // C# m_projIconMappings.Add("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", 2); // VB m_projIconMappings.Add("{00000001-0000-0000-0000-000000000000}", 5); // List all the countable file types (so we don't try to count .dll's, // images, executables, etc. m_countableTypes = new System.Collections.Specialized.StringCollection(); #if IMPR2 countingAlgorithms = AddInTree.BuildItems<CountingAlgorithmDescriptor> ("/AddIns/LineCounter/CountingAlgorithms", this); // Iterate through algorithms to fill list of known countable types foreach (CountingAlgorithmDescriptor desc in countingAlgorithms) { m_countableTypes.AddRange(desc.extensions); } #else m_countableTypes.Add("*"); m_countableTypes.Add(".cs"); m_countableTypes.Add(".vb"); m_countableTypes.Add(".vj"); m_countableTypes.Add(".cpp"); m_countableTypes.Add(".cc"); m_countableTypes.Add(".cxx"); m_countableTypes.Add(".c"); m_countableTypes.Add(".hpp"); m_countableTypes.Add(".hh"); m_countableTypes.Add(".hxx"); m_countableTypes.Add(".h"); m_countableTypes.Add(".js"); m_countableTypes.Add(".cd"); m_countableTypes.Add(".resx"); m_countableTypes.Add(".res"); m_countableTypes.Add(".css"); m_countableTypes.Add(".htm"); m_countableTypes.Add(".html"); m_countableTypes.Add(".xml"); m_countableTypes.Add(".xsl"); m_countableTypes.Add(".xslt"); m_countableTypes.Add(".xsd"); m_countableTypes.Add(".config"); m_countableTypes.Add(".asax"); m_countableTypes.Add(".ascx"); m_countableTypes.Add(".asmx"); m_countableTypes.Add(".aspx"); m_countableTypes.Add(".ashx"); m_countableTypes.Add(".idl"); m_countableTypes.Add(".odl"); m_countableTypes.Add(".txt"); m_countableTypes.Add(".sql"); #endif // Map file extensions to icons for use in the file list m_fileIconMappings = new Dictionary<string, int>(33); m_fileIconMappings.Add("*", 0); m_fileIconMappings.Add(".cs", 1); m_fileIconMappings.Add(".vb", 2); m_fileIconMappings.Add(".vj", 3); m_fileIconMappings.Add(".cpp", 4); m_fileIconMappings.Add(".cc", 4); m_fileIconMappings.Add(".cxx", 4); m_fileIconMappings.Add(".c", 5); m_fileIconMappings.Add(".hpp", 6); m_fileIconMappings.Add(".hh", 6); m_fileIconMappings.Add(".hxx", 6); m_fileIconMappings.Add(".h", 6); m_fileIconMappings.Add(".js", 7); m_fileIconMappings.Add(".cd", 8); m_fileIconMappings.Add(".resx", 9); m_fileIconMappings.Add(".res", 9); m_fileIconMappings.Add(".css", 10); m_fileIconMappings.Add(".htm", 11); m_fileIconMappings.Add(".html", 11); m_fileIconMappings.Add(".xml", 12); m_fileIconMappings.Add(".xsl", 13); m_fileIconMappings.Add(".xslt", 13); m_fileIconMappings.Add(".xsd", 14); m_fileIconMappings.Add(".config", 15); m_fileIconMappings.Add(".asax", 16); m_fileIconMappings.Add(".ascx", 17); m_fileIconMappings.Add(".asmx", 18); m_fileIconMappings.Add(".aspx", 19); m_fileIconMappings.Add(".ashx", 0); m_fileIconMappings.Add(".idl", 0); m_fileIconMappings.Add(".odl", 0); m_fileIconMappings.Add(".txt", 0); m_fileIconMappings.Add(".sql", 0); // Prepare counting algorithm mappings CountLines countLinesGeneric = new CountLines(CountLinesGeneric); CountLines countLinesCStyle = new CountLines(CountLinesCStyle); CountLines countLinesVBStyle = new CountLines(CountLinesVBStyle); CountLines countLinesXMLStyle = new CountLines(CountLinesXMLStyle); m_countAlgorithms = new Dictionary<string, CountLines>(33); m_countAlgorithms.Add("*", countLinesGeneric); m_countAlgorithms.Add(".cs", countLinesCStyle); m_countAlgorithms.Add(".vb", countLinesVBStyle); m_countAlgorithms.Add(".vj", countLinesCStyle); m_countAlgorithms.Add(".js", countLinesCStyle); m_countAlgorithms.Add(".cpp", countLinesCStyle); m_countAlgorithms.Add(".cc", countLinesCStyle); m_countAlgorithms.Add(".cxx", countLinesCStyle); m_countAlgorithms.Add(".c", countLinesCStyle); m_countAlgorithms.Add(".hpp", countLinesCStyle); m_countAlgorithms.Add(".hh", countLinesCStyle); m_countAlgorithms.Add(".hxx", countLinesCStyle); m_countAlgorithms.Add(".h", countLinesCStyle); m_countAlgorithms.Add(".idl", countLinesCStyle); m_countAlgorithms.Add(".odl", countLinesCStyle); m_countAlgorithms.Add(".txt", countLinesGeneric); m_countAlgorithms.Add(".xml", countLinesXMLStyle); m_countAlgorithms.Add(".xsl", countLinesXMLStyle); m_countAlgorithms.Add(".xslt", countLinesXMLStyle); m_countAlgorithms.Add(".xsd", countLinesXMLStyle); m_countAlgorithms.Add(".config", countLinesXMLStyle); m_countAlgorithms.Add(".res", countLinesGeneric); m_countAlgorithms.Add(".resx", countLinesXMLStyle); m_countAlgorithms.Add(".aspx", countLinesXMLStyle); m_countAlgorithms.Add(".ascx", countLinesXMLStyle); m_countAlgorithms.Add(".ashx", countLinesXMLStyle); m_countAlgorithms.Add(".asmx", countLinesXMLStyle); m_countAlgorithms.Add(".asax", countLinesXMLStyle); m_countAlgorithms.Add(".htm", countLinesXMLStyle); m_countAlgorithms.Add(".html", countLinesXMLStyle); m_countAlgorithms.Add(".css", countLinesCStyle); m_countAlgorithms.Add(".sql", countLinesGeneric); m_countAlgorithms.Add(".cd", countLinesGeneric); }
/// <summary> /// 进行各种统计的函数 /// </summary> /// <param name="s"></param> static void Operate(string[] args) { string file = null; List <string> textlist = new List <string>(); List <string> outputlist = new List <string>(); const string i = "-i", n = "-n", o = "-o", m = "-m"; string[] phrase = null; string[] word_frequency = null; List <string> list = new List <string>(); foreach (var s in args) { list.Add(s); } int j = 0; foreach (var s in list) { if (s == i) { file = list[j + 1]; if (OpenFile(file, ref textlist)) { } else { Console.WriteLine("打开文件失败!1"); } break; } ++j; } CountCharacters character = new CountCharacters(textlist); string ctr = character.Count_character(); Console.WriteLine(ctr); CountWords word = new CountWords(textlist); string ws = word.Count_word(); Console.WriteLine(ws); CountLines lines = new CountLines(textlist); string ls = lines.Count_line(); Console.WriteLine(ls); for (int k = 0; k < list.LongCount(); ++k) { if (list[k] == m) { int num = int.Parse(list[++k]); CountWords words = new CountWords(textlist); phrase = words.Count_Phrase(num); } else if (list[k] == n) { int num = int.Parse(list[++k]); CountWords words = new CountWords(textlist); word_frequency = words.Count_word_frequency(num); } else { continue; } } outputlist.Add(ctr); outputlist.Add(ws); outputlist.Add(ls); outputlist.Add("\r"); Console.WriteLine(); if (word_frequency != null) { foreach (var s in word_frequency) { outputlist.Add(s); Console.WriteLine(s); } } outputlist.Add("\r"); Console.WriteLine(); if (phrase != null) { foreach (var s in phrase) { outputlist.Add(s); } } for (int l = 0; l < list.LongCount(); ++l) { if (list[l] == o) { string outfile = list[++l]; if (WriteFile(outfile, outputlist)) { break; } else { Console.WriteLine("打开文件失败"); break; } } } }
public void CountLinesTest() { string text = "If you're going to try, go all the way. Otherwise, don't even start."; CountLines lines = new CountLines(text); //Assert.Fail(); }