Skip to content

Commit f01f57a

Browse files
committed
Run removeEmpty on all tokenize calls
This is the most likely behavior that users will want. Should it not be desired for whatever reason, subclasses may override the removeEmpty field. Fixes #64
1 parent 091aeef commit f01f57a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

diff.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@
3333
function clonePath(path) {
3434
return { newPos: path.newPos, components: path.components.slice(0) };
3535
}
36-
function removeEmpty(array) {
37-
var ret = [];
38-
for (var i = 0; i < array.length; i++) {
39-
if (array[i]) {
40-
ret.push(array[i]);
41-
}
42-
}
43-
return ret;
44-
}
4536
function escapeHTML(s) {
4637
var n = s;
4738
n = n.replace(/&/g, '&amp;');
@@ -170,8 +161,8 @@
170161
return done([{ value: newString, added: true }]);
171162
}
172163

173-
newString = this.tokenize(newString);
174-
oldString = this.tokenize(oldString);
164+
newString = this.removeEmpty(this.tokenize(newString));
165+
oldString = this.removeEmpty(this.tokenize(oldString));
175166

176167
var newLen = newString.length, oldLen = oldString.length;
177168
var editLength = 1;
@@ -293,6 +284,15 @@
293284
var reWhitespace = /\S/;
294285
return left === right || (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right));
295286
},
287+
removeEmpty: function(array) {
288+
var ret = [];
289+
for (var i = 0; i < array.length; i++) {
290+
if (array[i]) {
291+
ret.push(array[i]);
292+
}
293+
}
294+
return ret;
295+
},
296296
tokenize: function(value) {
297297
return value.split('');
298298
}
@@ -303,12 +303,12 @@
303303
var WordDiff = new Diff(true);
304304
var WordWithSpaceDiff = new Diff();
305305
WordDiff.tokenize = WordWithSpaceDiff.tokenize = function(value) {
306-
return removeEmpty(value.split(/(\s+|\b)/));
306+
return value.split(/(\s+|\b)/);
307307
};
308308

309309
var CssDiff = new Diff(true);
310310
CssDiff.tokenize = function(value) {
311-
return removeEmpty(value.split(/([{}:;,]|\s+)/));
311+
return value.split(/([{}:;,]|\s+)/);
312312
};
313313

314314
var LineDiff = new Diff();
@@ -367,7 +367,7 @@
367367

368368
var SentenceDiff = new Diff();
369369
SentenceDiff.tokenize = function(value) {
370-
return removeEmpty(value.split(/(\S.+?[.!?])(?=\s+|$)/));
370+
return value.split(/(\S.+?[.!?])(?=\s+|$)/);
371371
};
372372

373373
var JsonDiff = new Diff();

0 commit comments

Comments
 (0)