IsUsingLine() публичный статический Метод

public static IsUsingLine ( string line ) : bool
line string
Результат bool
Пример #1
0
        protected virtual void ProcessLine(FilePreProcessorContext context, string line, bool isBeforeCode)
        {
            Guard.AgainstNullArgument("context", context);

            if (PreProcessorUtil.IsUsingLine(line))
            {
                var @using = PreProcessorUtil.GetPath(PreProcessorUtil.UsingString, line);
                if (!context.UsingStatements.Contains(@using))
                {
                    context.UsingStatements.Add(@using);
                }

                return;
            }

            if (PreProcessorUtil.IsRLine(line))
            {
                if (isBeforeCode)
                {
                    var reference = PreProcessorUtil.GetPath(PreProcessorUtil.RString, line);
                    if (!string.IsNullOrWhiteSpace(reference) && !context.References.Contains(reference))
                    {
                        context.References.Add(reference);
                    }
                }

                return;
            }

            if (PreProcessorUtil.IsLoadLine(line))
            {
                if (isBeforeCode)
                {
                    var filePath = PreProcessorUtil.GetPath(PreProcessorUtil.LoadString, line);
                    if (!string.IsNullOrWhiteSpace(filePath) && !context.LoadedScripts.Contains(filePath))
                    {
                        ParseFile(filePath, context);
                    }
                }

                return;
            }

            // If we've reached this, the line is part of the body...
            context.Body.Add(line);
        }
Пример #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);
        }
Пример #3
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);
        }