public static int CountLinesOfCode(string sourceCode) { var blockCommentState = new BlockCommentState(); var sourceCodeLines = sourceCode.SplitLinesToArray(); return(sourceCodeLines.Count(x => IsCodeLine(x, blockCommentState))); }
private static bool IsCodeLine(string sourceCodeLine, BlockCommentState blockCommentState) { sourceCodeLine = sourceCodeLine.Trim(); if (sourceCodeLine.StartsWith ("/*")) { blockCommentState.IsActive = true; return HasBlockCommentTerminator(sourceCodeLine) && IsBlockCommentTerminatedBeforeEOL(sourceCodeLine); } if (sourceCodeLine.EndsWith ("*/")) { blockCommentState.IsActive = false; return false; } return blockCommentState.IsNotActive && sourceCodeLine.ContainsText() && IsNotSingleLineComment(sourceCodeLine); }
private static bool IsCodeLine(string sourceCodeLine, BlockCommentState blockCommentState) { sourceCodeLine = sourceCodeLine.Trim(); if (sourceCodeLine.StartsWith("/*")) { blockCommentState.IsActive = true; return(HasBlockCommentTerminator(sourceCodeLine) && IsBlockCommentTerminatedBeforeEOL(sourceCodeLine)); } if (sourceCodeLine.EndsWith("*/")) { blockCommentState.IsActive = false; return(false); } return(blockCommentState.IsNotActive && sourceCodeLine.ContainsText() && IsNotSingleLineComment(sourceCodeLine)); }
public static int CountLinesOfCode(string sourceCode) { var blockCommentState = new BlockCommentState(); var sourceCodeLines = sourceCode.SplitLinesToArray(); return sourceCodeLines.Count(x => IsCodeLine(x, blockCommentState)); }