コード例 #1
0
ファイル: DiffEngine.cs プロジェクト: layomia/dotnet_arcade
        private static IEnumerable <DiffLine> FixupCloseBraces(IEnumerable <DiffLine> lines, CancellationToken cancellationToken)
        {
            var startLineStack = new Stack <DiffLine>();

            foreach (var diffLine in lines)
            {
                cancellationToken.ThrowIfCancellationRequested();

                int      braceDelta = GetBraceDelta(diffLine);
                DiffLine result     = diffLine;

                for (var i = braceDelta; i > 0; i--)
                {
                    startLineStack.Push(diffLine);
                }

                for (var i = braceDelta; i < 0 && startLineStack.Count > 0; i++)
                {
                    DiffLine     startLine     = startLineStack.Pop();
                    DiffLineKind fixedLineKind = startLine.Kind;
                    if (result.Kind != fixedLineKind)
                    {
                        result = new DiffLine(fixedLineKind, diffLine.Tokens);
                    }
                }

                yield return(result);
            }
        }
コード例 #2
0
ファイル: DiffEngine.cs プロジェクト: layomia/dotnet_arcade
        private static IEnumerable <DiffLine> GetLines(IEnumerable <DiffToken> tokens, CancellationToken cancellationToken)
        {
            var lines             = new List <DiffLine>();
            var currentLineTokens = new List <DiffToken>();

            foreach (var diffToken in tokens)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (diffToken.Kind != DiffTokenKind.LineBreak)
                {
                    currentLineTokens.Add(diffToken);
                }
                else
                {
                    DiffLineKind kind = GetDiffLineKind(currentLineTokens);
                    var          line = new DiffLine(kind, currentLineTokens);
                    lines.Add(line);
                    currentLineTokens.Clear();
                }
            }

            // HACH: Fixup lines that only have closing brace but
            return(FixupCloseBraces(lines, cancellationToken));
        }
コード例 #3
0
ファイル: DiffEngine.cs プロジェクト: layomia/dotnet_arcade
        private static int GetBraceDelta(DiffLine diffLine)
        {
            int openBraces = 0;

            foreach (var symbol in diffLine.Tokens.Where(t => t.Kind == DiffTokenKind.Symbol))
            {
                switch (symbol.Text)
                {
                case "{":
                    openBraces++;
                    break;

                case "}":
                    openBraces--;
                    break;
                }
            }

            return(openBraces);
        }