break;
}
}
if (split == -1)
{
throw new PatchException("Missing split divider in context patch");
}
int baseIdx = 0;
int modifiedIdx = split + 1;
List<String> unifiedLines = new ArrayList<String>(hunk.lines.size());
for (; baseIdx < split || modifiedIdx < hunk.lines.size(); )
{
String baseLine = baseIdx < split ? hunk.lines.get(baseIdx) : "~";
String modifiedLine = modifiedIdx < hunk.lines.size() ? hunk.lines.get(modifiedIdx) : "~";
if (baseLine.startsWith("- "))
{
unifiedLines.add("-" + baseLine.substring(2));
unifiedHunk.baseCount++;
baseIdx++;
}
else if (modifiedLine.startsWith("+ "))
{
unifiedLines.add("+" + modifiedLine.substring(2));
unifiedHunk.modifiedCount++;
modifiedIdx++;
}
else if (baseLine.startsWith("! "))
{
unifiedLines.add("-" + baseLine.substring(2));
unifiedHunk.baseCount++;
baseIdx++;
}
else if (modifiedLine.startsWith("! "))
{
unifiedLines.add("+" + modifiedLine.substring(2));
unifiedHunk.modifiedCount++;
modifiedIdx++;
}
else if (baseLine.startsWith(" ") && modifiedLine.startsWith(" "))
{
unifiedLines.add(baseLine.substring(1));
unifiedHunk.baseCount++;
unifiedHunk.modifiedCount++;
baseIdx++;
modifiedIdx++;
}
else if (baseLine.startsWith(" "))
{
unifiedLines.add(baseLine.substring(1));
unifiedHunk.baseCount++;
unifiedHunk.modifiedCount++;
baseIdx++;
}
else if (modifiedLine.startsWith(" "))
{
unifiedLines.add(modifiedLine.substring(1));
unifiedHunk.baseCount++;
unifiedHunk.modifiedCount++;
modifiedIdx++;
}
else
{
throw new PatchException("Invalid context patch: " + baseLine);
}
}
unifiedHunk.lines = unifiedLines;
return unifiedHunk;
}