forked from lxm_front/Mergely
refactor: Split code into individual files and tidier code (#160)
* refactor: split code into separate files * chore: removed unused test code * refactor: no longer depends on jQuery.extend * docs: merged changes into CHANGELOG.md Co-authored-by: Jamie Peabody <jpeabody@axway.com>
This commit is contained in:
28
src/diff-parser.js
Normal file
28
src/diff-parser.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const changeExp = new RegExp(/(^(?![><\-])*\d+(?:,\d+)?)([acd])(\d+(?:,\d+)?)/);
|
||||
|
||||
function DiffParser(diff) {
|
||||
const changes = [];
|
||||
let change_id = 0;
|
||||
// parse diff
|
||||
const diff_lines = diff.split(/\n/);
|
||||
for (var i = 0; i < diff_lines.length; ++i) {
|
||||
if (diff_lines[i].length == 0) continue;
|
||||
const change = {};
|
||||
const test = changeExp.exec(diff_lines[i]);
|
||||
if (test == null) continue;
|
||||
// lines are zero-based
|
||||
const fr = test[1].split(',');
|
||||
change['lhs-line-from'] = fr[0] - 1;
|
||||
if (fr.length == 1) change['lhs-line-to'] = fr[0] - 1;
|
||||
else change['lhs-line-to'] = fr[1] - 1;
|
||||
const to = test[3].split(',');
|
||||
change['rhs-line-from'] = to[0] - 1;
|
||||
if (to.length == 1) change['rhs-line-to'] = to[0] - 1;
|
||||
else change['rhs-line-to'] = to[1] - 1;
|
||||
change['op'] = test[2];
|
||||
changes[change_id++] = change;
|
||||
}
|
||||
return changes;
|
||||
};
|
||||
|
||||
module.exports = DiffParser;
|
||||
Reference in New Issue
Block a user