3. [代码][JavaScript]代码 跳至
/*
* Compare str
* @example var result = htmldiff.compare('str1','str2');
*
*
*/
var htmldiff = {
MODE_CHARACTER: 1,MODE_TAG: 2,MODE_WHITESPACE: 3,
ACTION_EQUAL: 1,ACTION_DELETE: 2,ACTION_INSERT: 3,ACTION_NONE: 4,ACTION_REPLACE: 5,
specialCaseOpeningTags: new Array('\s]+', '\s]+', '\s]+', '\s]+', '\s]+', '\s]+', '\s]+', '\s]+', '\s]+', '\s]+'),
specialCaseClosingTags: new Array('', '', '', '', '', '', '', '', '', ''),
content: '',
wordIndices: '',
oldWords: '',newWords: '',
compare: function(str1, str2) {
this.content = new Array();
this.wordIndices = new Array();
this.oldWords = this.ConvertHtmlToListOfWords(str1);
this.newWords = this.ConvertHtmlToListOfWords(str2);
this.wordIndices = this.IndexNewWords(this.newWords);
var b = this.Operations();
for (var c = 0; c = k) break;
newMatchLength = (c[a - 1] ? c[a - 1] : 0) + 1;
d[a] = newMatchLength;
if (newMatchLength > n) {
f = i - newMatchLength + 1;
m = a - newMatchLength + 1;
n = newMatchLength;
}
}
c = d;
}
return n != 0 ? this.Match(f, m, n) : null;
},
IndexNewWords: function(d) {
var b = new Array();
for (var i = 0; i ';
d.push(e);
e = '';
if (this.IsWhiteSpace(c))
f = this.MODE_WHITESPACE;
else
f = this.MODE_CHARACTER;
} else
e = e + c;
break;
case this.MODE_WHITESPACE:
if (this.IsStartOfTag(c)) {
if (e)
d.push(e);
e = '' + c + '';
},
ExtractConsecutiveWords: function(d, f) {
var e = false;
for (var b = 0; b 0)
d.splice(0, e);
return {items: a,words: d};
} else {
a = d;
d = new Array();
return {items: a,words: d};
}
},
IsTag: function(b) {
var a = this.IsOpeningTag(b) || this.IsClosingTag(b);
return a;
},
IsOpeningTag: function(a) {
return /^s*]+>s*$/.test(a);
},
IsClosingTag: function(a) {
return /^s*]+>s*$/.test(a);
},
IsStartOfTag: function(a) {
return a == "";
},
IsWhiteSpace: function(a) {
return /s/.test(a);
},
isNaW: function(b) {
return /[^ -€]/.test(b);
},
array_slice: function(a, b, c, d) {
return a.slice(b, c);
},
Match: function(b, d, a) {
var c = {
StartInOld: b,
StartInNew: d,
Size: a
};
c.EndInOld = function() {
return b + a;
};
c.EndInNew = function() {
return d + a;
};
return c;
},
Operation: function(c, b, a, f, d) {
var e = {
Action: c,
StartInOld: b,
EndInOld: a,
StartInNew: f,
EndInNew: d
};
return e;
}
};
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!











