IsNonDirectiveLine() public static method

public static IsNonDirectiveLine ( string line ) : bool
line string
return bool
示例#1
0
        protected virtual void InsertLineDirective(string path, List <string> fileLines)
        {
            Guard.AgainstNullArgument("fileLines", fileLines);

            var bodyIndex = fileLines.FindIndex(line => PreProcessorUtil.IsNonDirectiveLine(line) && !PreProcessorUtil.IsUsingLine(line));

            if (bodyIndex == -1)
            {
                return;
            }

            var directiveLine = string.Format("#line {0} \"{1}\"", bodyIndex + 1, path);

            fileLines.Insert(bodyIndex, directiveLine);
        }
示例#2
0
        private string ParseFile(string path, IEnumerable <string> file, ref List <string> usings, ref List <string> rs, ref List <string> loads)
        {
            var fileList  = file.ToList();
            var firstCode = fileList.FindIndex(l => PreProcessorUtil.IsNonDirectiveLine(l));

            var firstBody = fileList.FindIndex(l => PreProcessorUtil.IsNonDirectiveLine(l) && !PreProcessorUtil.IsUsingLine(l));

            // add #line before the actual code begins
            // +1 because we are in a zero indexed list, but line numbers are 1 indexed
            // we need to keep the original position of the actual line
            if (firstBody != -1)
            {
                _logger.DebugFormat("Added #line statement for file {0} at line {1}", path, firstBody);
                fileList.Insert(firstBody, string.Format(@"#line {0} ""{1}""", firstBody + 1, path));
            }

            for (var i = 0; i < fileList.Count; i++)
            {
                var line = fileList[i];
                if (PreProcessorUtil.IsUsingLine(line))
                {
                    usings.Add(line);
                }
                else if (PreProcessorUtil.IsRLine(line))
                {
                    if (i < firstCode)
                    {
                        rs.Add(line);
                    }
                    else
                    {
                        fileList[i] = string.Empty;
                    }
                }
                else if (PreProcessorUtil.IsLoadLine(line))
                {
                    if ((i < firstCode || firstCode < 0) && !loads.Contains(line))
                    {
                        var filepath    = PreProcessorUtil.GetPath(PreProcessorUtil.LoadString, line);
                        var filecontent = _fileSystem.IsPathRooted(filepath)
                                              ? _fileSystem.ReadFileLines(filepath)
                                              : _fileSystem.ReadFileLines(_fileSystem.CurrentDirectory + @"\" + filepath);

                        if (filecontent != null)
                        {
                            loads.Add(line);
                            _logger.DebugFormat("Parsing file {0}", path);
                            var parsed = ParseFile(filepath, filecontent, ref usings, ref rs, ref loads);
                            fileList[i] = parsed;
                        }
                    }
                    else
                    {
                        fileList[i] = string.Empty;
                    }
                }
            }

            var result = string.Join(_fileSystem.NewLine, fileList.Where(line => !PreProcessorUtil.IsUsingLine(line) && !PreProcessorUtil.IsRLine(line)));

            return(result);
        }