|
33 | 33 | function clonePath(path) {
|
34 | 34 | return { newPos: path.newPos, components: path.components.slice(0) };
|
35 | 35 | }
|
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 |
| - } |
45 | 36 | function escapeHTML(s) {
|
46 | 37 | var n = s;
|
47 | 38 | n = n.replace(/&/g, '&');
|
|
170 | 161 | return done([{ value: newString, added: true }]);
|
171 | 162 | }
|
172 | 163 |
|
173 |
| - newString = this.tokenize(newString); |
174 |
| - oldString = this.tokenize(oldString); |
| 164 | + newString = this.removeEmpty(this.tokenize(newString)); |
| 165 | + oldString = this.removeEmpty(this.tokenize(oldString)); |
175 | 166 |
|
176 | 167 | var newLen = newString.length, oldLen = oldString.length;
|
177 | 168 | var editLength = 1;
|
|
293 | 284 | var reWhitespace = /\S/;
|
294 | 285 | return left === right || (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right));
|
295 | 286 | },
|
| 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 | + }, |
296 | 296 | tokenize: function(value) {
|
297 | 297 | return value.split('');
|
298 | 298 | }
|
|
303 | 303 | var WordDiff = new Diff(true);
|
304 | 304 | var WordWithSpaceDiff = new Diff();
|
305 | 305 | WordDiff.tokenize = WordWithSpaceDiff.tokenize = function(value) {
|
306 |
| - return removeEmpty(value.split(/(\s+|\b)/)); |
| 306 | + return value.split(/(\s+|\b)/); |
307 | 307 | };
|
308 | 308 |
|
309 | 309 | var CssDiff = new Diff(true);
|
310 | 310 | CssDiff.tokenize = function(value) {
|
311 |
| - return removeEmpty(value.split(/([{}:;,]|\s+)/)); |
| 311 | + return value.split(/([{}:;,]|\s+)/); |
312 | 312 | };
|
313 | 313 |
|
314 | 314 | var LineDiff = new Diff();
|
|
367 | 367 |
|
368 | 368 | var SentenceDiff = new Diff();
|
369 | 369 | SentenceDiff.tokenize = function(value) {
|
370 |
| - return removeEmpty(value.split(/(\S.+?[.!?])(?=\s+|$)/)); |
| 370 | + return value.split(/(\S.+?[.!?])(?=\s+|$)/); |
371 | 371 | };
|
372 | 372 |
|
373 | 373 | var JsonDiff = new Diff();
|
|
0 commit comments