public override int parseBody(Patch script, int end)
{
byte[] buf = File.Buffer;
int c = RawParseUtils.nextLF(buf, StartOffset);
_old.ForEach(coi =>
{
coi.LinesAdded = 0;
coi.LinesDeleted = 0;
coi.LinesContext = 0;
});
LinesContext = 0;
int nAdded = 0;
for (int eol; c < end; c = eol)
{
eol = RawParseUtils.nextLF(buf, c);
if (eol - c < _old.Count + 1)
{
// Line isn't long enough to mention the state of each
// ancestor. It must be the end of the hunk.
break;
}
bool break_scan = false;
switch (buf[c])
{
case (byte)' ':
case (byte)'-':
case (byte)'+':
break;
default:
// Line can't possibly be part of this hunk; the first
// ancestor information isn't recognizable.
//
break_scan = true;
break;
}
if (break_scan)
{
break;
}
int localcontext = 0;
for (int ancestor = 0; ancestor < _old.Count; ancestor++)
{
switch (buf[c + ancestor])
{
case (byte)' ':
localcontext++;
_old[ancestor].LinesContext++;
continue;
case (byte)'-':
_old[ancestor].LinesDeleted++;
continue;
case (byte)'+':
_old[ancestor].LinesAdded++;
nAdded++;
continue;
default:
break_scan = true;
break;
}
if (break_scan)
{
break;
}
}
if (break_scan)
{
break;
}
if (localcontext == _old.Count)
{
LinesContext++;
}
}
for (int ancestor = 0; ancestor < _old.Count; ancestor++)
{
CombinedOldImage o = _old[ancestor];
int cmp = o.LinesContext + o.LinesDeleted;
if (cmp < o.LineCount)
{
int missingCnt = o.LineCount - cmp;
script.error(buf, StartOffset, "Truncated hunk, at least "
+ missingCnt + " lines is missing for ancestor "
+ (ancestor + 1));
}
}
if (LinesContext + nAdded < NewLineCount)
{
int missingCount = NewLineCount - (LinesContext + nAdded);
script.error(buf, StartOffset, "Truncated hunk, at least "
+ missingCount + " new lines is missing");
}
return(c);
}