Exemple #1
0
        private bool TryGetLineRange(string query, out CodeRange codeRange, bool withL = true)
        {
            codeRange = null;
            if (string.IsNullOrEmpty(query))
            {
                return(false);
            }

            int startLine, endLine;

            var splitLine = query.Split(new[] { '-' });

            if (splitLine.Length > 2)
            {
                return(false);
            }

            var result = TryGetLineNumber(splitLine[0], out startLine, withL);

            endLine = startLine;

            if (splitLine.Length > 1)
            {
                result &= TryGetLineNumber(splitLine[1], out endLine, withL);
            }

            codeRange = new CodeRange {
                Start = startLine, End = endLine
            };

            return(result);
        }
        public Dictionary <string, CodeRange> GetAllTags(string[] lines, ref HashSet <int> tagLines)
        {
            var result   = new Dictionary <string, CodeRange>(StringComparer.OrdinalIgnoreCase);
            var tagStack = new Stack <string>();

            for (int index = 0; index < lines.Length; index++)
            {
                var line = lines[index];

                string tagName;

                if (MatchTag(line, EndLineTemplate, out tagName))
                {
                    tagLines.Add(index);
                    if (!IsEndLineContainsTagName)
                    {
                        tagName = tagStack.Count > 0 ? tagStack.Pop() : string.Empty;
                    }

                    if (!result.ContainsKey(tagName))
                    {
                        Logger.LogWarning($"Can't find startTag {tagName}");
                    }
                    else
                    {
                        if (result[tagName].End == 0)
                        {
                            // we meet the first end tag, ignore the following ones
                            result[tagName].End = index;
                        }
                    }

                    continue;
                }

                if (MatchTag(line, StartLineTemplate, out tagName))
                {
                    tagLines.Add(index);
                    result[tagName] = new CodeRange {
                        Start = index + 2
                    };
                    tagStack.Push(tagName);
                }
            }

            return(result);
        }