fictioneer/js/diff-match-patch.js
2024-05-10 00:05:05 +02:00

1 line
21 KiB
JavaScript

var diff_match_patch=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32},DIFF_DELETE=-1,DIFF_INSERT=1,DIFF_EQUAL=0;diff_match_patch.Diff=function(t,i){this[0]=t,this[1]=i},diff_match_patch.Diff.prototype.length=2,diff_match_patch.Diff.prototype.toString=function(){return this[0]+","+this[1]},diff_match_patch.prototype.diff_main=function(t,i,h,f){if(void 0===f&&(f=0>=this.Diff_Timeout?Number.MAX_VALUE:(new Date).getTime()+1e3*this.Diff_Timeout),null==t||null==i)throw Error("Null input. (diff_main)");if(t==i)return t?[new diff_match_patch.Diff(DIFF_EQUAL,t)]:[];void 0===h&&(h=!0);var e=h,n=this.diff_commonPrefix(t,i);h=t.substring(0,n),t=t.substring(n),i=i.substring(n),n=this.diff_commonSuffix(t,i);var a=t.substring(t.length-n);return t=t.substring(0,t.length-n),i=i.substring(0,i.length-n),t=this.diff_compute_(t,i,e,f),h&&t.unshift(new diff_match_patch.Diff(DIFF_EQUAL,h)),a&&t.push(new diff_match_patch.Diff(DIFF_EQUAL,a)),this.diff_cleanupMerge(t),t},diff_match_patch.prototype.diff_compute_=function(t,i,h,f){if(!t)return[new diff_match_patch.Diff(DIFF_INSERT,i)];if(!i)return[new diff_match_patch.Diff(DIFF_DELETE,t)];var e=t.length>i.length?t:i,n=t.length>i.length?i:t,a=e.indexOf(n);return-1!=a?(h=[new diff_match_patch.Diff(DIFF_INSERT,e.substring(0,a)),new diff_match_patch.Diff(DIFF_EQUAL,n),new diff_match_patch.Diff(DIFF_INSERT,e.substring(a+n.length))],t.length>i.length&&(h[0][0]=h[2][0]=DIFF_DELETE),h):1==n.length?[new diff_match_patch.Diff(DIFF_DELETE,t),new diff_match_patch.Diff(DIFF_INSERT,i)]:(e=this.diff_halfMatch_(t,i))?(i=e[1],n=e[3],t=e[4],e=this.diff_main(e[0],e[2],h,f),h=this.diff_main(i,n,h,f),e.concat([new diff_match_patch.Diff(DIFF_EQUAL,t)],h)):h&&100<t.length&&100<i.length?this.diff_lineMode_(t,i,f):this.diff_bisect_(t,i,f)},diff_match_patch.prototype.diff_lineMode_=function(t,i,h){var f=this.diff_linesToChars_(t,i);t=f.chars1,i=f.chars2,f=f.lineArray,t=this.diff_main(t,i,!1,h),this.diff_charsToLines_(t,f),this.diff_cleanupSemantic(t),t.push(new diff_match_patch.Diff(DIFF_EQUAL,""));for(var e=f=i=0,n="",a="";i<t.length;){switch(t[i][0]){case DIFF_INSERT:e++,a+=t[i][1];break;case DIFF_DELETE:f++,n+=t[i][1];break;case DIFF_EQUAL:if(1<=f&&1<=e){for(t.splice(i-f-e,f+e),i=i-f-e,e=(f=this.diff_main(n,a,!1,h)).length-1;0<=e;e--)t.splice(i,0,f[e]);i+=f.length}f=e=0,a=n=""}i++}return t.pop(),t},diff_match_patch.prototype.diff_bisect_=function(t,i,h){for(var f=t.length,e=i.length,n=Math.ceil((f+e)/2),a=2*n,r=Array(a),s=Array(a),_=0;_<a;_++)r[_]=-1,s[_]=-1;r[n+1]=0,s[n+1]=0;for(var c=0!=(_=f-e)%2,l=0,g=0,o=0,p=0,d=0;d<n&&!((new Date).getTime()>h);d++){for(var u=-d+l;u<=d-g;u+=2){for(var m=n+u,F=u==-d||u!=d&&r[m-1]<r[m+1]?r[m+1]:r[m-1]+1,D=F-u;F<f&&D<e&&t.charAt(F)==i.charAt(D);)F++,D++;if(r[m]=F,F>f)g+=2;else if(D>e)l+=2;else if(c&&(0<=(m=n+_-u)&&m<a&&-1!=s[m])){var E=f-s[m];if(F>=E)return this.diff_bisectSplit_(t,i,F,D,h)}}for(u=-d+o;u<=d-p;u+=2){for(m=n+u,F=(E=u==-d||u!=d&&s[m-1]<s[m+1]?s[m+1]:s[m-1]+1)-u;E<f&&F<e&&t.charAt(f-E-1)==i.charAt(e-F-1);)E++,F++;if(s[m]=E,E>f)p+=2;else if(F>e)o+=2;else if(!c&&(0<=(m=n+_-u)&&m<a&&-1!=r[m]&&(D=n+(F=r[m])-m,F>=(E=f-E))))return this.diff_bisectSplit_(t,i,F,D,h)}}return[new diff_match_patch.Diff(DIFF_DELETE,t),new diff_match_patch.Diff(DIFF_INSERT,i)]},diff_match_patch.prototype.diff_bisectSplit_=function(t,i,h,f,e){var n=t.substring(0,h),a=i.substring(0,f);return t=t.substring(h),i=i.substring(f),n=this.diff_main(n,a,!1,e),e=this.diff_main(t,i,!1,e),n.concat(e)},diff_match_patch.prototype.diff_linesToChars_=function(t,i){function h(t){for(var i="",h=0,a=-1,r=f.length;a<t.length-1;){-1==(a=t.indexOf("\n",h))&&(a=t.length-1);var s=t.substring(h,a+1);void 0!==e[s]?i+=String.fromCharCode(e[s]):(r==n&&(s=t.substring(h),a=t.length),i+=String.fromCharCode(r),e[s]=r,f[r++]=s),h=a+1}return i}var f=[],e={};f[0]="";var n=4e4,a=h(t);return n=65535,{chars1:a,chars2:h(i),lineArray:f}},diff_match_patch.prototype.diff_charsToLines_=function(t,i){for(var h=0;h<t.length;h++){for(var f=t[h][1],e=[],n=0;n<f.length;n++)e[n]=i[f.charCodeAt(n)];t[h][1]=e.join("")}},diff_match_patch.prototype.diff_commonPrefix=function(t,i){if(!t||!i||t.charAt(0)!=i.charAt(0))return 0;for(var h=0,f=Math.min(t.length,i.length),e=f,n=0;h<e;)t.substring(n,e)==i.substring(n,e)?n=h=e:f=e,e=Math.floor((f-h)/2+h);return e},diff_match_patch.prototype.diff_commonSuffix=function(t,i){if(!t||!i||t.charAt(t.length-1)!=i.charAt(i.length-1))return 0;for(var h=0,f=Math.min(t.length,i.length),e=f,n=0;h<e;)t.substring(t.length-e,t.length-n)==i.substring(i.length-e,i.length-n)?n=h=e:f=e,e=Math.floor((f-h)/2+h);return e},diff_match_patch.prototype.diff_commonOverlap_=function(t,i){var h=t.length,f=i.length;if(0==h||0==f)return 0;if(h>f?t=t.substring(h-f):h<f&&(i=i.substring(0,h)),h=Math.min(h,f),t==i)return h;f=0;for(var e=1;;){var n=t.substring(h-e);if(-1==(n=i.indexOf(n)))return f;e+=n,0!=n&&t.substring(h-e)!=i.substring(0,e)||(f=e,e++)}},diff_match_patch.prototype.diff_halfMatch_=function(t,i){function h(t,i,h){for(var f,e,a,r,s=t.substring(h,h+Math.floor(t.length/4)),_=-1,c="";-1!=(_=i.indexOf(s,_+1));){var l=n.diff_commonPrefix(t.substring(h),i.substring(_)),g=n.diff_commonSuffix(t.substring(0,h),i.substring(0,_));c.length<g+l&&(c=i.substring(_-g,_)+i.substring(_,_+l),f=t.substring(0,h-g),e=t.substring(h+l),a=i.substring(0,_-g),r=i.substring(_+l))}return 2*c.length>=t.length?[f,e,a,r,c]:null}if(0>=this.Diff_Timeout)return null;var f=t.length>i.length?t:i,e=t.length>i.length?i:t;if(4>f.length||2*e.length<f.length)return null;var n=this,a=h(f,e,Math.ceil(f.length/4));if(f=h(f,e,Math.ceil(f.length/2)),!a&&!f)return null;if(a=f?a&&a[4].length>f[4].length?a:f:a,t.length>i.length){f=a[0],e=a[1];var r=a[2],s=a[3]}else r=a[0],s=a[1],f=a[2],e=a[3];return[f,e,r,s,a[4]]},diff_match_patch.prototype.diff_cleanupSemantic=function(t){for(var i=!1,h=[],f=0,e=null,n=0,a=0,r=0,s=0,_=0;n<t.length;)t[n][0]==DIFF_EQUAL?(h[f++]=n,a=s,r=_,_=s=0,e=t[n][1]):(t[n][0]==DIFF_INSERT?s+=t[n][1].length:_+=t[n][1].length,e&&e.length<=Math.max(a,r)&&e.length<=Math.max(s,_)&&(t.splice(h[f-1],0,new diff_match_patch.Diff(DIFF_DELETE,e)),t[h[f-1]+1][0]=DIFF_INSERT,f--,n=0<--f?h[f-1]:-1,_=s=r=a=0,e=null,i=!0)),n++;for(i&&this.diff_cleanupMerge(t),this.diff_cleanupSemanticLossless(t),n=1;n<t.length;)t[n-1][0]==DIFF_DELETE&&t[n][0]==DIFF_INSERT&&(i=t[n-1][1],h=t[n][1],(f=this.diff_commonOverlap_(i,h))>=(e=this.diff_commonOverlap_(h,i))?(f>=i.length/2||f>=h.length/2)&&(t.splice(n,0,new diff_match_patch.Diff(DIFF_EQUAL,h.substring(0,f))),t[n-1][1]=i.substring(0,i.length-f),t[n+1][1]=h.substring(f),n++):(e>=i.length/2||e>=h.length/2)&&(t.splice(n,0,new diff_match_patch.Diff(DIFF_EQUAL,i.substring(0,e))),t[n-1][0]=DIFF_INSERT,t[n-1][1]=h.substring(0,h.length-e),t[n+1][0]=DIFF_DELETE,t[n+1][1]=i.substring(e),n++),n++),n++},diff_match_patch.prototype.diff_cleanupSemanticLossless=function(t){function i(t,i){if(!t||!i)return 6;var h=t.charAt(t.length-1),f=i.charAt(0),e=h.match(diff_match_patch.nonAlphaNumericRegex_),n=f.match(diff_match_patch.nonAlphaNumericRegex_),a=e&&h.match(diff_match_patch.whitespaceRegex_),r=n&&f.match(diff_match_patch.whitespaceRegex_);h=a&&h.match(diff_match_patch.linebreakRegex_),f=r&&f.match(diff_match_patch.linebreakRegex_);var s=h&&t.match(diff_match_patch.blanklineEndRegex_),_=f&&i.match(diff_match_patch.blanklineStartRegex_);return s||_?5:h||f?4:e&&!a&&r?3:a||r?2:e||n?1:0}for(var h=1;h<t.length-1;){if(t[h-1][0]==DIFF_EQUAL&&t[h+1][0]==DIFF_EQUAL){var f=t[h-1][1],e=t[h][1],n=t[h+1][1],a=this.diff_commonSuffix(f,e);if(a){var r=e.substring(e.length-a);f=f.substring(0,f.length-a),e=r+e.substring(0,e.length-a),n=r+n}a=f,r=e;for(var s=n,_=i(f,e)+i(e,n);e.charAt(0)===n.charAt(0);){f+=e.charAt(0),e=e.substring(1)+n.charAt(0),n=n.substring(1);var c=i(f,e)+i(e,n);c>=_&&(_=c,a=f,r=e,s=n)}t[h-1][1]!=a&&(a?t[h-1][1]=a:(t.splice(h-1,1),h--),t[h][1]=r,s?t[h+1][1]=s:(t.splice(h+1,1),h--))}h++}},diff_match_patch.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,diff_match_patch.whitespaceRegex_=/\s/,diff_match_patch.linebreakRegex_=/[\r\n]/,diff_match_patch.blanklineEndRegex_=/\n\r?\n$/,diff_match_patch.blanklineStartRegex_=/^\r?\n\r?\n/,diff_match_patch.prototype.diff_cleanupEfficiency=function(t){for(var i=!1,h=[],f=0,e=null,n=0,a=!1,r=!1,s=!1,_=!1;n<t.length;)t[n][0]==DIFF_EQUAL?(t[n][1].length<this.Diff_EditCost&&(s||_)?(h[f++]=n,a=s,r=_,e=t[n][1]):(f=0,e=null),s=_=!1):(t[n][0]==DIFF_DELETE?_=!0:s=!0,e&&(a&&r&&s&&_||e.length<this.Diff_EditCost/2&&3==a+r+s+_)&&(t.splice(h[f-1],0,new diff_match_patch.Diff(DIFF_DELETE,e)),t[h[f-1]+1][0]=DIFF_INSERT,f--,e=null,a&&r?(s=_=!0,f=0):(n=0<--f?h[f-1]:-1,s=_=!1),i=!0)),n++;i&&this.diff_cleanupMerge(t)},diff_match_patch.prototype.diff_cleanupMerge=function(t){t.push(new diff_match_patch.Diff(DIFF_EQUAL,""));for(var i,h=0,f=0,e=0,n="",a="";h<t.length;)switch(t[h][0]){case DIFF_INSERT:e++,a+=t[h][1],h++;break;case DIFF_DELETE:f++,n+=t[h][1],h++;break;case DIFF_EQUAL:1<f+e?(0!==f&&0!==e&&(0!==(i=this.diff_commonPrefix(a,n))&&(0<h-f-e&&t[h-f-e-1][0]==DIFF_EQUAL?t[h-f-e-1][1]+=a.substring(0,i):(t.splice(0,0,new diff_match_patch.Diff(DIFF_EQUAL,a.substring(0,i))),h++),a=a.substring(i),n=n.substring(i)),0!==(i=this.diff_commonSuffix(a,n))&&(t[h][1]=a.substring(a.length-i)+t[h][1],a=a.substring(0,a.length-i),n=n.substring(0,n.length-i))),h-=f+e,t.splice(h,f+e),n.length&&(t.splice(h,0,new diff_match_patch.Diff(DIFF_DELETE,n)),h++),a.length&&(t.splice(h,0,new diff_match_patch.Diff(DIFF_INSERT,a)),h++),h++):0!==h&&t[h-1][0]==DIFF_EQUAL?(t[h-1][1]+=t[h][1],t.splice(h,1)):h++,f=e=0,a=n=""}for(""===t[t.length-1][1]&&t.pop(),f=!1,h=1;h<t.length-1;)t[h-1][0]==DIFF_EQUAL&&t[h+1][0]==DIFF_EQUAL&&(t[h][1].substring(t[h][1].length-t[h-1][1].length)==t[h-1][1]?(t[h][1]=t[h-1][1]+t[h][1].substring(0,t[h][1].length-t[h-1][1].length),t[h+1][1]=t[h-1][1]+t[h+1][1],t.splice(h-1,1),f=!0):t[h][1].substring(0,t[h+1][1].length)==t[h+1][1]&&(t[h-1][1]+=t[h+1][1],t[h][1]=t[h][1].substring(t[h+1][1].length)+t[h+1][1],t.splice(h+1,1),f=!0)),h++;f&&this.diff_cleanupMerge(t)},diff_match_patch.prototype.diff_xIndex=function(t,i){var h,f=0,e=0,n=0,a=0;for(h=0;h<t.length&&(t[h][0]!==DIFF_INSERT&&(f+=t[h][1].length),t[h][0]!==DIFF_DELETE&&(e+=t[h][1].length),!(f>i));h++)n=f,a=e;return t.length!=h&&t[h][0]===DIFF_DELETE?a:a+(i-n)},diff_match_patch.prototype.diff_prettyHtml=function(t){for(var i=[],h=/&/g,f=/</g,e=/>/g,n=/\n/g,a=0;a<t.length;a++){var r=t[a][0],s=t[a][1].replace(h,"&amp;").replace(f,"&lt;").replace(e,"&gt;").replace(n,"&para;<br>");switch(r){case DIFF_INSERT:i[a]='<ins style="background:#e6ffe6;">'+s+"</ins>";break;case DIFF_DELETE:i[a]='<del style="background:#ffe6e6;">'+s+"</del>";break;case DIFF_EQUAL:i[a]="<span>"+s+"</span>"}}return i.join("")},diff_match_patch.prototype.diff_text1=function(t){for(var i=[],h=0;h<t.length;h++)t[h][0]!==DIFF_INSERT&&(i[h]=t[h][1]);return i.join("")},diff_match_patch.prototype.diff_text2=function(t){for(var i=[],h=0;h<t.length;h++)t[h][0]!==DIFF_DELETE&&(i[h]=t[h][1]);return i.join("")},diff_match_patch.prototype.diff_levenshtein=function(t){for(var i=0,h=0,f=0,e=0;e<t.length;e++){var n=t[e][1];switch(t[e][0]){case DIFF_INSERT:h+=n.length;break;case DIFF_DELETE:f+=n.length;break;case DIFF_EQUAL:i+=Math.max(h,f),f=h=0}}return i+Math.max(h,f)},diff_match_patch.prototype.diff_toDelta=function(t){for(var i=[],h=0;h<t.length;h++)switch(t[h][0]){case DIFF_INSERT:i[h]="+"+encodeURI(t[h][1]);break;case DIFF_DELETE:i[h]="-"+t[h][1].length;break;case DIFF_EQUAL:i[h]="="+t[h][1].length}return i.join("\t").replace(/%20/g," ")},diff_match_patch.prototype.diff_fromDelta=function(t,i){for(var h=[],f=0,e=0,n=i.split(/\t/g),a=0;a<n.length;a++){var r=n[a].substring(1);switch(n[a].charAt(0)){case"+":try{h[f++]=new diff_match_patch.Diff(DIFF_INSERT,decodeURI(r))}catch(t){throw Error("Illegal escape in diff_fromDelta: "+r)}break;case"-":case"=":var s=parseInt(r,10);if(isNaN(s)||0>s)throw Error("Invalid number in diff_fromDelta: "+r);r=t.substring(e,e+=s),"="==n[a].charAt(0)?h[f++]=new diff_match_patch.Diff(DIFF_EQUAL,r):h[f++]=new diff_match_patch.Diff(DIFF_DELETE,r);break;default:if(n[a])throw Error("Invalid diff operation in diff_fromDelta: "+n[a])}}if(e!=t.length)throw Error("Delta length ("+e+") does not equal source text length ("+t.length+").");return h},diff_match_patch.prototype.match_main=function(t,i,h){if(null==t||null==i||null==h)throw Error("Null input. (match_main)");return h=Math.max(0,Math.min(h,t.length)),t==i?0:t.length?t.substring(h,h+i.length)==i?h:this.match_bitap_(t,i,h):-1},diff_match_patch.prototype.match_bitap_=function(t,i,h){function f(t,f){var e=t/i.length,a=Math.abs(h-f);return n.Match_Distance?e+a/n.Match_Distance:a?1:e}if(i.length>this.Match_MaxBits)throw Error("Pattern too long for this browser.");var e=this.match_alphabet_(i),n=this,a=this.Match_Threshold,r=t.indexOf(i,h);-1!=r&&(a=Math.min(f(0,r),a),-1!=(r=t.lastIndexOf(i,h+i.length))&&(a=Math.min(f(0,r),a)));var s=1<<i.length-1;r=-1;for(var _,c,l,g=i.length+t.length,o=0;o<i.length;o++){for(_=0,c=g;_<c;)f(o,h+c)<=a?_=c:g=c,c=Math.floor((g-_)/2+_);g=c,_=Math.max(1,h-c+1);var p=Math.min(h+c,t.length)+i.length;for((c=Array(p+2))[p+1]=(1<<o)-1;p>=_;p--){var d=e[t.charAt(p-1)];if(c[p]=0===o?(c[p+1]<<1|1)&d:(c[p+1]<<1|1)&d|(l[p+1]|l[p])<<1|1|l[p+1],c[p]&s&&(d=f(o,p-1))<=a){if(a=d,!((r=p-1)>h))break;_=Math.max(1,2*h-r)}}if(f(o+1,h)>a)break;l=c}return r},diff_match_patch.prototype.match_alphabet_=function(t){for(var i={},h=0;h<t.length;h++)i[t.charAt(h)]=0;for(h=0;h<t.length;h++)i[t.charAt(h)]|=1<<t.length-h-1;return i},diff_match_patch.prototype.patch_addContext_=function(t,i){if(0!=i.length){if(null===t.start2)throw Error("patch not initialized");for(var h=i.substring(t.start2,t.start2+t.length1),f=0;i.indexOf(h)!=i.lastIndexOf(h)&&h.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)f+=this.Patch_Margin,h=i.substring(t.start2-f,t.start2+t.length1+f);f+=this.Patch_Margin,(h=i.substring(t.start2-f,t.start2))&&t.diffs.unshift(new diff_match_patch.Diff(DIFF_EQUAL,h)),(f=i.substring(t.start2+t.length1,t.start2+t.length1+f))&&t.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,f)),t.start1-=h.length,t.start2-=h.length,t.length1+=h.length+f.length,t.length2+=h.length+f.length}},diff_match_patch.prototype.patch_make=function(t,i,h){if("string"==typeof t&&"string"==typeof i&&void 0===h){var f=t;2<(i=this.diff_main(f,i,!0)).length&&(this.diff_cleanupSemantic(i),this.diff_cleanupEfficiency(i))}else if(t&&"object"==typeof t&&void 0===i&&void 0===h)i=t,f=this.diff_text1(i);else if("string"==typeof t&&i&&"object"==typeof i&&void 0===h)f=t;else{if("string"!=typeof t||"string"!=typeof i||!h||"object"!=typeof h)throw Error("Unknown call format to patch_make.");f=t,i=h}if(0===i.length)return[];h=[],t=new diff_match_patch.patch_obj;for(var e=0,n=0,a=0,r=f,s=0;s<i.length;s++){var _=i[s][0],c=i[s][1];switch(e||_===DIFF_EQUAL||(t.start1=n,t.start2=a),_){case DIFF_INSERT:t.diffs[e++]=i[s],t.length2+=c.length,f=f.substring(0,a)+c+f.substring(a);break;case DIFF_DELETE:t.length1+=c.length,t.diffs[e++]=i[s],f=f.substring(0,a)+f.substring(a+c.length);break;case DIFF_EQUAL:c.length<=2*this.Patch_Margin&&e&&i.length!=s+1?(t.diffs[e++]=i[s],t.length1+=c.length,t.length2+=c.length):c.length>=2*this.Patch_Margin&&e&&(this.patch_addContext_(t,r),h.push(t),t=new diff_match_patch.patch_obj,e=0,r=f,n=a)}_!==DIFF_INSERT&&(n+=c.length),_!==DIFF_DELETE&&(a+=c.length)}return e&&(this.patch_addContext_(t,r),h.push(t)),h},diff_match_patch.prototype.patch_deepCopy=function(t){for(var i=[],h=0;h<t.length;h++){var f=t[h],e=new diff_match_patch.patch_obj;e.diffs=[];for(var n=0;n<f.diffs.length;n++)e.diffs[n]=new diff_match_patch.Diff(f.diffs[n][0],f.diffs[n][1]);e.start1=f.start1,e.start2=f.start2,e.length1=f.length1,e.length2=f.length2,i[h]=e}return i},diff_match_patch.prototype.patch_apply=function(t,i){if(0==t.length)return[i,[]];t=this.patch_deepCopy(t);var h=this.patch_addPadding(t);i=h+i+h,this.patch_splitMax(t);for(var f=0,e=[],n=0;n<t.length;n++){var a=t[n].start2+f,r=this.diff_text1(t[n].diffs),s=-1;if(r.length>this.Match_MaxBits){var _=this.match_main(i,r.substring(0,this.Match_MaxBits),a);-1!=_&&(-1==(s=this.match_main(i,r.substring(r.length-this.Match_MaxBits),a+r.length-this.Match_MaxBits))||_>=s)&&(_=-1)}else _=this.match_main(i,r,a);if(-1==_)e[n]=!1,f-=t[n].length2-t[n].length1;else if(e[n]=!0,f=_-a,r==(a=-1==s?i.substring(_,_+r.length):i.substring(_,s+this.Match_MaxBits)))i=i.substring(0,_)+this.diff_text2(t[n].diffs)+i.substring(_+r.length);else if(a=this.diff_main(r,a,!1),r.length>this.Match_MaxBits&&this.diff_levenshtein(a)/r.length>this.Patch_DeleteThreshold)e[n]=!1;else{var c;for(this.diff_cleanupSemanticLossless(a),r=0,s=0;s<t[n].diffs.length;s++){var l=t[n].diffs[s];l[0]!==DIFF_EQUAL&&(c=this.diff_xIndex(a,r)),l[0]===DIFF_INSERT?i=i.substring(0,_+c)+l[1]+i.substring(_+c):l[0]===DIFF_DELETE&&(i=i.substring(0,_+c)+i.substring(_+this.diff_xIndex(a,r+l[1].length))),l[0]!==DIFF_DELETE&&(r+=l[1].length)}}}return[i=i.substring(h.length,i.length-h.length),e]},diff_match_patch.prototype.patch_addPadding=function(t){for(var i=this.Patch_Margin,h="",f=1;f<=i;f++)h+=String.fromCharCode(f);for(f=0;f<t.length;f++)t[f].start1+=i,t[f].start2+=i;var e=(f=t[0]).diffs;if(0==e.length||e[0][0]!=DIFF_EQUAL)e.unshift(new diff_match_patch.Diff(DIFF_EQUAL,h)),f.start1-=i,f.start2-=i,f.length1+=i,f.length2+=i;else if(i>e[0][1].length){var n=i-e[0][1].length;e[0][1]=h.substring(e[0][1].length)+e[0][1],f.start1-=n,f.start2-=n,f.length1+=n,f.length2+=n}return 0==(e=(f=t[t.length-1]).diffs).length||e[e.length-1][0]!=DIFF_EQUAL?(e.push(new diff_match_patch.Diff(DIFF_EQUAL,h)),f.length1+=i,f.length2+=i):i>e[e.length-1][1].length&&(n=i-e[e.length-1][1].length,e[e.length-1][1]+=h.substring(0,n),f.length1+=n,f.length2+=n),h},diff_match_patch.prototype.patch_splitMax=function(t){for(var i=this.Match_MaxBits,h=0;h<t.length;h++)if(!(t[h].length1<=i)){var f=t[h];t.splice(h--,1);for(var e=f.start1,n=f.start2,a="";0!==f.diffs.length;){var r=new diff_match_patch.patch_obj,s=!0;for(r.start1=e-a.length,r.start2=n-a.length,""!==a&&(r.length1=r.length2=a.length,r.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,a)));0!==f.diffs.length&&r.length1<i-this.Patch_Margin;){a=f.diffs[0][0];var _=f.diffs[0][1];a===DIFF_INSERT?(r.length2+=_.length,n+=_.length,r.diffs.push(f.diffs.shift()),s=!1):a===DIFF_DELETE&&1==r.diffs.length&&r.diffs[0][0]==DIFF_EQUAL&&_.length>2*i?(r.length1+=_.length,e+=_.length,s=!1,r.diffs.push(new diff_match_patch.Diff(a,_)),f.diffs.shift()):(_=_.substring(0,i-r.length1-this.Patch_Margin),r.length1+=_.length,e+=_.length,a===DIFF_EQUAL?(r.length2+=_.length,n+=_.length):s=!1,r.diffs.push(new diff_match_patch.Diff(a,_)),_==f.diffs[0][1]?f.diffs.shift():f.diffs[0][1]=f.diffs[0][1].substring(_.length))}a=(a=this.diff_text2(r.diffs)).substring(a.length-this.Patch_Margin),""!==(_=this.diff_text1(f.diffs).substring(0,this.Patch_Margin))&&(r.length1+=_.length,r.length2+=_.length,0!==r.diffs.length&&r.diffs[r.diffs.length-1][0]===DIFF_EQUAL?r.diffs[r.diffs.length-1][1]+=_:r.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,_))),s||t.splice(++h,0,r)}}},diff_match_patch.prototype.patch_toText=function(t){for(var i=[],h=0;h<t.length;h++)i[h]=t[h];return i.join("")},diff_match_patch.prototype.patch_fromText=function(t){var i=[];if(!t)return i;t=t.split("\n");for(var h=0,f=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;h<t.length;){var e=t[h].match(f);if(!e)throw Error("Invalid patch string: "+t[h]);var n=new diff_match_patch.patch_obj;for(i.push(n),n.start1=parseInt(e[1],10),""===e[2]?(n.start1--,n.length1=1):"0"==e[2]?n.length1=0:(n.start1--,n.length1=parseInt(e[2],10)),n.start2=parseInt(e[3],10),""===e[4]?(n.start2--,n.length2=1):"0"==e[4]?n.length2=0:(n.start2--,n.length2=parseInt(e[4],10)),h++;h<t.length;){e=t[h].charAt(0);try{var a=decodeURI(t[h].substring(1))}catch(t){throw Error("Illegal escape in patch_fromText: "+a)}if("-"==e)n.diffs.push(new diff_match_patch.Diff(DIFF_DELETE,a));else if("+"==e)n.diffs.push(new diff_match_patch.Diff(DIFF_INSERT,a));else if(" "==e)n.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL,a));else{if("@"==e)break;if(""!==e)throw Error('Invalid patch mode "'+e+'" in: '+a)}h++}}return i},diff_match_patch.patch_obj=function(){this.diffs=[],this.start2=this.start1=null,this.length2=this.length1=0},diff_match_patch.patch_obj.prototype.toString=function(){for(var t,i=["@@ -"+(0===this.length1?this.start1+",0":1==this.length1?this.start1+1:this.start1+1+","+this.length1)+" +"+(0===this.length2?this.start2+",0":1==this.length2?this.start2+1:this.start2+1+","+this.length2)+" @@\n"],h=0;h<this.diffs.length;h++){switch(this.diffs[h][0]){case DIFF_INSERT:t="+";break;case DIFF_DELETE:t="-";break;case DIFF_EQUAL:t=" "}i[h+1]=t+encodeURI(this.diffs[h][1])+"\n"}return i.join("").replace(/%20/g," ")},this.diff_match_patch=diff_match_patch,this.DIFF_DELETE=DIFF_DELETE,this.DIFF_INSERT=DIFF_INSERT,this.DIFF_EQUAL=DIFF_EQUAL;