Example #1
0
 private static bool End(Edit edit, int a, int b)
 {
     return edit.EndA <= a && edit.EndB <= b;
 }
Example #2
0
        /// <summary>
        /// Returns a list describing the content edits performed within the hunk.
        /// </summary>
        /// <returns></returns>
        internal EditList ToEditList()
        {
            var r = new EditList();
            byte[] buf = Buffer;
            int c = RawParseUtils.nextLF(buf, _startOffset);
            int oLine = OldStartLine;
            int nLine = NewStartLine;
            Edit inEdit = null;

            for (; c < Buffer.Length; c = RawParseUtils.nextLF(buf, c))
            {
                bool breakScan;

                switch (buf[c])
                {
                    case (byte)' ':
                    case (byte)'\n':
                        inEdit = null;
                        oLine++;
                        nLine++;
                        continue;

                    case (byte)'-':
                        if (inEdit == null)
                        {
                            inEdit = new Edit(oLine - 1, nLine - 1);
                            r.Add(inEdit);
                        }
                        oLine++;
                        inEdit.ExtendA();
                        continue;

                    case (byte)'+':
                        if (inEdit == null)
                        {
                            inEdit = new Edit(oLine - 1, nLine - 1);
                            r.Add(inEdit);
                        }
                        nLine++;
                        inEdit.ExtendB();
                        continue;

                    case (byte)'\\': // Matches "\ No newline at end of file"
                        continue;

                    default:
                        breakScan = true;
                        break;
                }

                if (breakScan)
                {
                    break;
                }
            }

            return r;
        }