neocities/public/js/xregexp-min.js
2015-10-13 15:59:13 -07:00

2 lines
No EOL
11 KiB
JavaScript

//XRegExp 3.0.0 <xregexp.com> MIT License
var XRegExp=function(a){"use strict";function u(a,d,e,f,g){var h;if(a[c]={captureNames:d},g)return a;if(a.__proto__)a.__proto__=b.prototype;else for(h in b.prototype)a[h]=b.prototype[h];return a[c].source=e,a[c].flags=f?f.split("").sort().join(""):f,a}function v(a){return e.replace.call(a,/([\s\S])(?=[\s\S]*\1)/g,"")}function w(d,f){if(!b.isRegExp(d))throw new TypeError("Type RegExp expected");var g=d[c]||{},h=y(d),i="",j="",k=null,l=null;return f=f||{},f.removeG&&(j+="g"),f.removeY&&(j+="y"),j&&(h=e.replace.call(h,new RegExp("["+j+"]+","g"),"")),f.addG&&(i+="g"),f.addY&&(i+="y"),i&&(h=v(h+i)),f.isInternalOnly||(g.source!==a&&(k=g.source),null!=g.flags&&(l=i?v(g.flags+i):g.flags)),d=u(new RegExp(d.source,h),z(d)?g.captureNames.slice(0):null,k,l,f.isInternalOnly)}function x(a){return parseInt(a,16)}function y(a){return q?a.flags:e.exec.call(/\/([a-z]*)$/i,RegExp.prototype.toString.call(a))[1]}function z(a){return!(!a[c]||!a[c].captureNames)}function A(a){return parseInt(a,10).toString(16)}function B(a,b){var d,c=a.length;for(d=0;c>d;++d)if(a[d]===b)return d;return-1}function C(a,b){return s.call(a)==="[object "+b+"]"}function D(a,b,c){return e.test.call(c.indexOf("x")>-1?/^(?:\s+|#.*|\(\?#[^)]*\))*(?:[?*+]|{\d+(?:,\d*)?})/:/^(?:\(\?#[^)]*\))*(?:[?*+]|{\d+(?:,\d*)?})/,a.slice(b))}function E(a){for(;a.length<4;)a="0"+a;return a}function F(a,b){var c;if(v(b)!==b)throw new SyntaxError("Invalid duplicate regex flag "+b);for(a=e.replace.call(a,/^\(\?([\w$]+)\)/,function(a,c){if(e.test.call(/[gy]/,c))throw new SyntaxError("Cannot use flag g or y in mode modifier "+a);return b=v(b+c),""}),c=0;c<b.length;++c)if(!r[b.charAt(c)])throw new SyntaxError("Unknown regex flag "+b.charAt(c));return{pattern:a,flags:b}}function G(a){var c={};return C(a,"String")?(b.forEach(a,/[^\s,]+/,function(a){c[a]=!0}),c):a}function H(a){if(!/^[\w$]$/.test(a))throw new Error("Flag must be a single character A-Za-z0-9_$");r[a]=!0}function I(a,c,d,e,f){for(var k,l,g=i.length,h=a.charAt(d),j=null;g--;)if(l=i[g],!(l.leadChar&&l.leadChar!==h||l.scope!==e&&"all"!==l.scope||l.flag&&-1===c.indexOf(l.flag))&&(k=b.exec(a,l.regex,d,"sticky"))){j={matchLength:k[0].length,output:l.handler.call(f,k,e,c),reparse:l.reparse};break}return j}function J(a){d.astral=a}function K(a){RegExp.prototype.exec=(a?f:e).exec,RegExp.prototype.test=(a?f:e).test,String.prototype.match=(a?f:e).match,String.prototype.replace=(a?f:e).replace,String.prototype.split=(a?f:e).split,d.natives=a}function L(a){if(null==a)throw new TypeError("Cannot convert null or undefined to object");return a}var b,t,c="xregexp",d={astral:!1,natives:!1},e={exec:RegExp.prototype.exec,test:RegExp.prototype.test,match:String.prototype.match,replace:String.prototype.replace,split:String.prototype.split},f={},g={},h={},i=[],j="default",k="class",l={"default":/\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9]\d*|x[\dA-Fa-f]{2}|u(?:[\dA-Fa-f]{4}|{[\dA-Fa-f]+})|c[A-Za-z]|[\s\S])|\(\?[:=!]|[?*+]\?|{\d+(?:,\d*)?}\??|[\s\S]/,"class":/\\(?:[0-3][0-7]{0,2}|[4-7][0-7]?|x[\dA-Fa-f]{2}|u(?:[\dA-Fa-f]{4}|{[\dA-Fa-f]+})|c[A-Za-z]|[\s\S])|[\s\S]/},m=/\$(?:{([\w$]+)}|(\d\d?|[\s\S]))/g,n=e.exec.call(/()??/,"")[1]===a,o=function(){var a=!0;try{new RegExp("","u")}catch(b){a=!1}return a}(),p=function(){var a=!0;try{new RegExp("","y")}catch(b){a=!1}return a}(),q=/a/.flags!==a,r={g:!0,i:!0,m:!0,u:o,y:p},s={}.toString;return b=function(c,d){var n,o,p,q,r,f={hasNamedCapture:!1,captureNames:[]},g=j,i="",m=0;if(b.isRegExp(c)){if(d!==a)throw new TypeError("Cannot supply flags when copying a RegExp");return w(c)}if(c=c===a?"":String(c),d=d===a?"":String(d),b.isInstalled("astral")&&-1===d.indexOf("A")&&(d+="A"),h[c]||(h[c]={}),!h[c][d]){for(n=F(c,d),q=n.pattern,r=n.flags;m<q.length;){do n=I(q,r,m,g,f),n&&n.reparse&&(q=q.slice(0,m)+n.output+q.slice(m+n.matchLength));while(n&&n.reparse);n?(i+=n.output,m+=n.matchLength||1):(o=b.exec(q,l[g],m,"sticky")[0],i+=o,m+=o.length,"["===o&&g===j?g=k:"]"===o&&g===k&&(g=j))}h[c][d]={pattern:e.replace.call(i,/\(\?:\)(?=\(\?:\))|^\(\?:\)|\(\?:\)$/g,""),flags:e.replace.call(r,/[^gimuy]+/g,""),captures:f.hasNamedCapture?f.captureNames:null}}return p=h[c][d],u(new RegExp(p.pattern,p.flags),p.captures,c,d)},b.prototype=new RegExp,b.version="3.0.0",b.addToken=function(a,c,d){d=d||{};var g,f=d.optionalFlags;if(d.flag&&H(d.flag),f)for(f=e.split.call(f,""),g=0;g<f.length;++g)H(f[g]);i.push({regex:w(a,{addG:!0,addY:p,isInternalOnly:!0}),handler:c,scope:d.scope||j,flag:d.flag,reparse:d.reparse,leadChar:d.leadChar}),b.cache.flush("patterns")},b.cache=function(a,c){return g[a]||(g[a]={}),g[a][c]||(g[a][c]=b(a,c))},b.cache.flush=function(a){"patterns"===a?h={}:g={}},b.escape=function(a){return e.replace.call(L(a),/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")},b.exec=function(a,b,d,e){var i,j,g="g",h=!1;return h=p&&!!(e||b.sticky&&e!==!1),h&&(g+="y"),b[c]=b[c]||{},j=b[c][g]||(b[c][g]=w(b,{addG:!0,addY:h,removeY:e===!1,isInternalOnly:!0})),j.lastIndex=d=d||0,i=f.exec.call(j,a),e&&i&&i.index!==d&&(i=null),b.global&&(b.lastIndex=i?j.lastIndex:0),i},b.forEach=function(a,c,d){for(var g,e=0,f=-1;g=b.exec(a,c,e);)d(g,++f,a,c),e=g.index+(g[0].length||1)},b.globalize=function(a){return w(a,{addG:!0})},b.install=function(a){a=G(a),!d.astral&&a.astral&&J(!0),!d.natives&&a.natives&&K(!0)},b.isInstalled=function(a){return!!d[a]},b.isRegExp=function(a){return"[object RegExp]"===s.call(a)},b.match=function(a,b,d){var h,i,f=b.global&&"one"!==d||"all"===d,g=(f?"g":"")+(b.sticky?"y":"")||"noGY";return b[c]=b[c]||{},i=b[c][g]||(b[c][g]=w(b,{addG:!!f,addY:!!b.sticky,removeG:"one"===d,isInternalOnly:!0})),h=e.match.call(L(a),i),b.global&&(b.lastIndex="one"===d&&h?h.index+h[0].length:0),f?h||[]:h&&h[0]},b.matchChain=function(a,c){return function d(a,e){var i,f=c[e].regex?c[e]:{regex:c[e]},g=[],h=function(a){if(f.backref){if(!(a.hasOwnProperty(f.backref)||+f.backref<a.length))throw new ReferenceError("Backreference to undefined group: "+f.backref);g.push(a[f.backref]||"")}else g.push(a[0])};for(i=0;i<a.length;++i)b.forEach(a[i],f.regex,h);return e!==c.length-1&&g.length?d(g,e+1):g}([a],0)},b.replace=function(a,d,e,g){var l,h=b.isRegExp(d),i=d.global&&"one"!==g||"all"===g,j=(i?"g":"")+(d.sticky?"y":"")||"noGY",k=d;return h?(d[c]=d[c]||{},k=d[c][j]||(d[c][j]=w(d,{addG:!!i,addY:!!d.sticky,removeG:"one"===g,isInternalOnly:!0}))):i&&(k=new RegExp(b.escape(String(d)),"g")),l=f.replace.call(L(a),k,e),h&&d.global&&(d.lastIndex=0),l},b.replaceEach=function(a,c){var d,e;for(d=0;d<c.length;++d)e=c[d],a=b.replace(a,e[0],e[1],e[2]);return a},b.split=function(a,b,c){return f.split.call(L(a),b,c)},b.test=function(a,c,d,e){return!!b.exec(a,c,d,e)},b.uninstall=function(a){a=G(a),d.astral&&a.astral&&J(!1),d.natives&&a.natives&&K(!1)},b.union=function(a,d){var i,j,k,m,f=/(\()(?!\?)|\\([1-9]\d*)|\\[\s\S]|\[(?:[^\\\]]|\\[\s\S])*]/g,g=[],h=0,l=function(a,b,c){var d=j[h-i];if(b){if(++h,d)return"(?<"+d+">"}else if(c)return"\\"+(+c+i);return a};if(!C(a,"Array")||!a.length)throw new TypeError("Must provide a nonempty array of patterns to merge");for(m=0;m<a.length;++m)k=a[m],b.isRegExp(k)?(i=h,j=k[c]&&k[c].captureNames||[],g.push(e.replace.call(b(k.source).source,f,l))):g.push(b.escape(k));return b(g.join("|"),d)},f.exec=function(b){var g,h,i,d=this.lastIndex,f=e.exec.apply(this,arguments);if(f){if(!n&&f.length>1&&B(f,"")>-1&&(h=w(this,{removeG:!0,isInternalOnly:!0}),e.replace.call(String(b).slice(f.index),h,function(){var c,b=arguments.length;for(c=1;b-2>c;++c)arguments[c]===a&&(f[c]=a)})),this[c]&&this[c].captureNames)for(i=1;i<f.length;++i)g=this[c].captureNames[i-1],g&&(f[g]=f[i]);this.global&&!f[0].length&&this.lastIndex>f.index&&(this.lastIndex=f.index)}return this.global||(this.lastIndex=d),f},f.test=function(a){return!!f.exec.call(this,a)},f.match=function(a){var c;if(b.isRegExp(a)){if(a.global)return c=e.match.apply(this,arguments),a.lastIndex=0,c}else a=new RegExp(a);return f.exec.call(a,L(this))},f.replace=function(d,f){var h,i,j,g=b.isRegExp(d);return g?(d[c]&&(i=d[c].captureNames),h=d.lastIndex):d+="",j=C(f,"Function")?e.replace.call(String(this),d,function(){var c,b=arguments;if(i)for(b[0]=new String(b[0]),c=0;c<i.length;++c)i[c]&&(b[0][i[c]]=b[c+1]);return g&&d.global&&(d.lastIndex=b[b.length-2]+b[0].length),f.apply(a,b)}):e.replace.call(null==this?this:String(this),d,function(){var a=arguments;return e.replace.call(String(f),m,function(b,c,d){var e;if(c){if(e=+c,e<=a.length-3)return a[e]||"";if(e=i?B(i,c):-1,0>e)throw new SyntaxError("Backreference to undefined group "+b);return a[e+1]||""}if("$"===d)return"$";if("&"===d||0===+d)return a[0];if("`"===d)return a[a.length-1].slice(0,a[a.length-2]);if("'"===d)return a[a.length-1].slice(a[a.length-2]+a[0].length);if(d=+d,!isNaN(d)){if(d>a.length-3)throw new SyntaxError("Backreference to undefined group "+b);return a[d]||""}throw new SyntaxError("Invalid token "+b)})}),g&&(d.global?d.lastIndex=0:d.lastIndex=h),j},f.split=function(c,d){if(!b.isRegExp(c))return e.split.apply(this,arguments);var j,f=String(this),g=[],h=c.lastIndex,i=0;return d=(d===a?-1:d)>>>0,b.forEach(f,c,function(a){a.index+a[0].length>i&&(g.push(f.slice(i,a.index)),a.length>1&&a.index<f.length&&Array.prototype.push.apply(g,a.slice(1)),j=a[0].length,i=a.index+j)}),i===f.length?(!e.test.call(c,"")||j)&&g.push(""):g.push(f.slice(i)),c.lastIndex=h,g.length>d?g.slice(0,d):g},t=b.addToken,t(/\\([ABCE-RTUVXYZaeg-mopqyz]|c(?![A-Za-z])|u(?![\dA-Fa-f]{4}|{[\dA-Fa-f]+})|x(?![\dA-Fa-f]{2}))/,function(a,b){if("B"===a[1]&&b===j)return a[0];throw new SyntaxError("Invalid escape "+a[0])},{scope:"all",leadChar:"\\"}),t(/\\u{([\dA-Fa-f]+)}/,function(a,b,c){var d=x(a[1]);if(d>1114111)throw new SyntaxError("Invalid Unicode code point "+a[0]);if(65535>=d)return"\\u"+E(A(d));if(o&&c.indexOf("u")>-1)return a[0];throw new SyntaxError("Cannot use Unicode code point above \\u{FFFF} without flag u")},{scope:"all",leadChar:"\\"}),t(/\[(\^?)]/,function(a){return a[1]?"[\\s\\S]":"\\b\\B"},{leadChar:"["}),t(/\(\?#[^)]*\)/,function(a,b,c){return D(a.input,a.index+a[0].length,c)?"":"(?:)"},{leadChar:"("}),t(/\s+|#.*/,function(a,b,c){return D(a.input,a.index+a[0].length,c)?"":"(?:)"},{flag:"x"}),t(/\./,function(){return"[\\s\\S]"},{flag:"s",leadChar:"."}),t(/\\k<([\w$]+)>/,function(a){var b=isNaN(a[1])?B(this.captureNames,a[1])+1:+a[1],c=a.index+a[0].length;if(!b||b>this.captureNames.length)throw new SyntaxError("Backreference to undefined group "+a[0]);return"\\"+b+(c===a.input.length||isNaN(a.input.charAt(c))?"":"(?:)")},{leadChar:"\\"}),t(/\\(\d+)/,function(a,b){if(!(b===j&&/^[1-9]/.test(a[1])&&+a[1]<=this.captureNames.length)&&"0"!==a[1])throw new SyntaxError("Cannot use octal escape or backreference to undefined group "+a[0]);return a[0]},{scope:"all",leadChar:"\\"}),t(/\(\?P?<([\w$]+)>/,function(a){if(!isNaN(a[1]))throw new SyntaxError("Cannot use integer as capture name "+a[0]);if("length"===a[1]||"__proto__"===a[1])throw new SyntaxError("Cannot use reserved word as capture name "+a[0]);if(B(this.captureNames,a[1])>-1)throw new SyntaxError("Cannot use same name for multiple groups "+a[0]);return this.captureNames.push(a[1]),this.hasNamedCapture=!0,"("},{leadChar:"("}),t(/\((?!\?)/,function(a,b,c){return c.indexOf("n")>-1?"(?:":(this.captureNames.push(null),"(")},{optionalFlags:"n",leadChar:"("}),b}();