/// <summary>统计行的详细信息</summary> private static void CountMoreAboutLine(string s, out int codeLineCount, out int emptyLineCount, out int commentLineCount) { codeLineCount = 0; //代码行 emptyLineCount = 0; //空行 commentLineCount = 0; //注释行 int charInALine = 0; //当前行可见字符数 int i = -1; CommentLineType CommentLine = CommentLineType.NonCommentLine; bool cancelCommentLine = false; foreach (char c in s) { i++; if (c == '\n' || i == s.Length - 1) { if (CommentLine == CommentLineType.SingleCommentLine) { commentLineCount++; CommentLine = CommentLineType.NonCommentLine; } else if ((CommentLine == CommentLineType.SeveralCommentLine || cancelCommentLine) && charInALine <= 1) { commentLineCount++; } else if (charInALine > 1) { codeLineCount++; } else { emptyLineCount++; } if (cancelCommentLine) { cancelCommentLine = false; } charInALine = 0; } if (charInALine <= 1 && c == '/' && i > 0 && s[i - 1] == '/') { CommentLine = CommentLineType.SingleCommentLine; } else if (c == '*' && i > 0 && s[i - 1] == '/') { CommentLine = CommentLineType.SeveralCommentLine; } else if (c == '/' && i > 0 && s[i - 1] == '*') { cancelCommentLine = true; CommentLine = CommentLineType.NonCommentLine; } else if (CommentLine == CommentLineType.NonCommentLine && !displayedCharDic.Contains(c)) { charInALine++; } } }
internal static void commentline(this TextWriter trapFile, CommentLine commentLine, CommentLineType type, string text, string rawtext) { trapFile.WriteTuple("commentline", commentLine, (int)type, text, rawtext); }