コード例 #1
0
        public HostsFile()
        {
            var path     = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + "\\drivers\\etc\\hosts";
            var contents = Common.Globals.ReadFile(path);

            using (var reader = new StringReader(contents))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Trim().StartsWith("#"))
                    {
                        CommentLines.Add(line);
                    }
                    else
                    {
                        var m = Regex.Match(line, @"\s*(\d+\.\d+\.\d+\.\d+)\s+([^\s]+)(\s+(#.*))?");
                        if (m.Success)
                        {
                            Entries[m.Groups[2].Value.ToLower()] = new HostEntry()
                            {
                                IpAddress = m.Groups[1].Value,
                                HostName  = m.Groups[2].Value.ToLower(),
                                Comment   = m.Groups[4].Success ? m.Groups[4].Value : ""
                            };
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: CommentProcessing.cs プロジェクト: lcartey/codeql
 /// <summary>
 ///     Adds a comment line to the this comment block.
 /// </summary>
 /// <param name="line">The line to add.</param>
 public void AddCommentLine(ICommentLine line)
 {
     Location = CommentLines.Count == 0 ?
                line.Location :
                Location.Create(line.Location.SourceTree, new TextSpan(Location.SourceSpan.Start, line.Location.SourceSpan.End - Location.SourceSpan.Start));
     CommentLines.Add(line);
 }
コード例 #3
0
ファイル: Parser.cs プロジェクト: SteGriff/SqlSherlock
        private void SaveCommentIfNonEmpty(string line)
        {
            string commentContent = line.StripSqlCommentMarkers();

            if (!string.IsNullOrEmpty(commentContent))
            {
                CommentLines.Add(commentContent);
            }
        }
コード例 #4
0
        public string GetPropertyValueString(string prop)
        {
            switch (prop)
            {
            case "codeLines":
                return(CodeLines?.ToString("N0") ?? string.Empty);

            case "commentedCodeLines":
                return(CommentedCodeLines?.ToString("N0") ?? string.Empty);

            case "commentLines":
                return(CommentLines?.ToString("N0") ?? string.Empty);

            case "coupling":
                return(Coupling?.ToString("N0") ?? string.Empty);

            case "fanIn":
                return(FanIn?.ToString("N0") ?? string.Empty);

            case "fanOut":
                return(FanOut?.ToString("N0") ?? string.Empty);

            case "cyclomaticComplexity":
                return(CyclomaticComplexity?.ToString("N0") ?? string.Empty);

            case "ratioCommentLinesCodeLines":
                return(RatioCommentLinesCodeLines?.ToString("N2") ?? string.Empty);

            case "halsteadProgramLength":
                return(HalsteadProgramLength?.ToString("N0") ?? string.Empty);

            case "halsteadProgramVocabulary":
                return(HalsteadProgramVocabulary?.ToString("N0") ?? string.Empty);

            case "halsteadVolume":
                return(HalsteadVolume?.ToString("N2") ?? string.Empty);

            case "distinctOperators":
                return(DistinctOperators?.ToString("N0") ?? string.Empty);

            case "distinctOperands":
                return(DistinctOperands?.ToString("N0") ?? string.Empty);

            case "integrationComplexity":
                return(IntegrationComplexity?.ToString("N0") ?? string.Empty);

            case "essentialComplexity":
                return(EssentialComplexity?.ToString("N0") ?? string.Empty);

            default:
                return(string.Empty);
            }
        }
コード例 #5
0
        /// <summary>
        ///     Determine whether commentlines should be merged.
        /// </summary>
        /// <param name="newLine">A comment line to be appended to this comment block.</param>
        /// <returns>Whether the new line should be appended to this block.</returns>
        public bool CombinesWith(ICommentLine newLine)
        {
            if (!CommentLines.Any())
            {
                return(true);
            }

            var sameFile   = Location.SourceTree == newLine.Location.SourceTree;
            var sameRow    = Location.EndLine() == newLine.Location.StartLine();
            var sameColumn = Location.EndLine() + 1 == newLine.Location.StartLine();
            var nextRow    = Location.StartColumn() == newLine.Location.StartColumn();
            var adjacent   = sameFile && (sameRow || (sameColumn && nextRow));

            return
                (newLine.Type == CommentLineType.MultilineContinuation ||
                 adjacent);
        }