Exemplo n.º 1
0
        /// <summary>Create <see cref="DiffLine"/>.</summary>
        /// <param name="state">Line state.</param>
        /// <param name="states">Line states.</param>
        /// <param name="nums">Line numbers.</param>
        /// <param name="text">Line text.</param>
        public DiffLine(DiffLineState state, DiffLineState[] states, int[] nums, string text, string ending = LineEnding.Lf)
        {
            Verify.Argument.IsNotNull(states, "states");
            Verify.Argument.IsNotNull(nums, "nums");

            _charPositions = -1;
            _text	= text;
            _state	= state;
            _states	= states;
            _nums	= nums;
            _ending	= ending;
        }
Exemplo n.º 2
0
        /// <summary>Create <see cref="DiffLine"/>.</summary>
        /// <param name="state">Line state.</param>
        /// <param name="states">Line states.</param>
        /// <param name="nums">Line numbers.</param>
        /// <param name="text">Line text.</param>
        public DiffLine(DiffLineState state, DiffLineState[] states, int[] nums, string text, string ending = LineEnding.Lf)
        {
            Verify.Argument.IsNotNull(states, nameof(states));
            Verify.Argument.IsNotNull(nums, nameof(nums));

            _charPositions = -1;
            _text          = text;
            _state         = state;
            _states        = states;
            _nums          = nums;
            _ending        = ending;
        }
Exemplo n.º 3
0
        private Brush GetLineBackgroundBrush(DiffLineState state)
        {
            switch (state)
            {
            case DiffLineState.Added:
                return(new SolidBrush(Style.Colors.LineAddedBackground));

            case DiffLineState.Removed:
                return(new SolidBrush(Style.Colors.LineRemovedBackground));

            case DiffLineState.Header:
                return(new SolidBrush(Style.Colors.LineHeaderBackground));

            default:
                return(new SolidBrush(Style.Colors.LineContextBackground));
            }
        }
Exemplo n.º 4
0
        public void Decrement(DiffLineState state)
        {
            switch (state)
            {
            case DiffLineState.Added:
                --_addedLinesCount;
                break;

            case DiffLineState.Removed:
                --_removedLinesCount;
                break;

            case DiffLineState.Context:
                --_contextLinesCount;
                break;

            default:
                --_headerLinesCount;
                break;
            }
        }
Exemplo n.º 5
0
 public void Increment(DiffLineState state)
 {
     switch(state)
     {
         case DiffLineState.Added:
             ++_addedLinesCount;
             break;
         case DiffLineState.Removed:
             ++_removedLinesCount;
             break;
         case DiffLineState.Context:
             ++_contextLinesCount;
             break;
         default:
             ++_headerLinesCount;
             break;
     }
 }
Exemplo n.º 6
0
        private DiffLine ReadDiffLine(int[] nums)
        {
            int[] lineNums = (int[])nums.Clone();
            int   nc       = nums.Length;
            var   states   = new DiffLineState[nc];

            if (CheckValue(NoNewlineHeader) || CheckValue(HunkHeader))
            {
                for (int i = 0; i < nc; ++i)
                {
                    states[i] = DiffLineState.Header;
                }
                return(new DiffLine(DiffLineState.Header, states, lineNums, ReadLine()));
            }
            var state = DiffLineState.Context;

            for (int i = 0; i < nc - 1; ++i)
            {
                switch (ReadChar())
                {
                case '-':
                    state     = DiffLineState.Removed;
                    states[i] = DiffLineState.Removed;
                    break;

                case '+':
                    state     = DiffLineState.Added;
                    states[i] = DiffLineState.Added;
                    break;

                case ' ':
                    states[i] = DiffLineState.Context;
                    break;

                default:
                    states[i] = DiffLineState.Context;
                    break;
                }
            }
            states[nc - 1] = DiffLineState.Context;
            switch (state)
            {
            case DiffLineState.Context:
                for (int i = 0; i < nc; ++i)
                {
                    ++nums[i];
                }
                break;

            case DiffLineState.Added:
                for (int i = 0; i < nc; ++i)
                {
                    if (states[i] == DiffLineState.Context)
                    {
                        ++nums[i];
                    }
                }
                break;

            case DiffLineState.Removed:
                for (int i = 0; i < nc - 1; ++i)
                {
                    if (states[i] == DiffLineState.Context)
                    {
                        states[i] = DiffLineState.NotPresent;
                    }
                    else if (states[i] == DiffLineState.Removed)
                    {
                        states[i] = DiffLineState.Context;
                        ++nums[i];
                    }
                }
                states[nc - 1] = DiffLineState.Removed;
                break;
            }
            int    eol = FindLfLineEnding();
            string ending;

            if (String[eol - 1] == '\r')
            {
                --eol;
                ending = LineEnding.CrLf;
            }
            else
            {
                ending = LineEnding.Lf;
            }
            var line = ReadStringUpTo(eol, ending.Length);

            return(new DiffLine(state, states, lineNums, line, ending));
        }
Exemplo n.º 7
0
 private Brush GetLineForegroundBrush(DiffLineState state)
 {
     switch(state)
     {
         case DiffLineState.Added:
             return new SolidBrush(Style.Colors.LineAddedForeground);
         case DiffLineState.Removed:
             return new SolidBrush(Style.Colors.LineRemovedForeground);
         case DiffLineState.Header:
             return new SolidBrush(Style.Colors.LineHeaderForeground);
         default:
             return new SolidBrush(Style.Colors.LineContextForeground);
     }
 }
Exemplo n.º 8
0
 private DiffLine ReadDiffLine(int[] nums)
 {
     int[] lineNums = (int[])nums.Clone();
     int nc = nums.Length;
     var states = new DiffLineState[nc];
     if(CheckValue(NoNewlineHeader) || CheckValue(HunkHeader))
     {
         for(int i = 0; i < nc; ++i)
         {
             states[i] = DiffLineState.Header;
         }
         return new DiffLine(DiffLineState.Header, states, lineNums, ReadLine());
     }
     var state = DiffLineState.Context;
     for(int i = 0; i < nc - 1; ++i)
     {
         switch(ReadChar())
         {
             case '-':
                 state = DiffLineState.Removed;
                 states[i] = DiffLineState.Removed;
                 break;
             case '+':
                 state = DiffLineState.Added;
                 states[i] = DiffLineState.Added;
                 break;
             case ' ':
                 states[i] = DiffLineState.Context;
                 break;
             default:
                 states[i] = DiffLineState.Context;
                 break;
         }
     }
     states[nc - 1] = DiffLineState.Context;
     switch(state)
     {
         case DiffLineState.Context:
             for(int i = 0; i < nc; ++i)
             {
                 ++nums[i];
             }
             break;
         case DiffLineState.Added:
             for(int i = 0; i < nc; ++i)
             {
                 if(states[i] == DiffLineState.Context)
                 {
                     ++nums[i];
                 }
             }
             break;
         case DiffLineState.Removed:
             for(int i = 0; i < nc - 1; ++i)
             {
                 if(states[i] == DiffLineState.Context)
                 {
                     states[i] = DiffLineState.NotPresent;
                 }
                 else if(states[i] == DiffLineState.Removed)
                 {
                     states[i] = DiffLineState.Context;
                     ++nums[i];
                 }
             }
             states[nc - 1] = DiffLineState.Removed;
             break;
     }
     int eol = FindLfLineEnding();
     string ending;
     if(String[eol - 1] == '\r')
     {
         --eol;
         ending = LineEnding.CrLf;
     }
     else
     {
         ending = LineEnding.Lf;
     }
     var line = ReadStringUpTo(eol, ending.Length);
     return new DiffLine(state, states, lineNums, line, ending);
 }