!function(a,b){"use strict";var c=b.prototype.trim,d=b.prototype.trimRight,e=b.prototype.trimLeft,f=function(a){return a*1||0},g=function(a,b){if(b<1)return"";var c="";while(b>0)b&1&&(c+=a),b>>=1,a+=a;return c},h=[].slice,i=function(a){return a==null?"\\s":a.source?a.source:"["+n.escapeRegExp(a)+"]"},j={lt:"<",gt:">",quot:'"',apos:"'",amp:"&"},k={};for(var l in j)k[j[l]]=l;var m=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}var c=g,d=function(){return d.cache.hasOwnProperty(arguments[0])||(d.cache[arguments[0]]=d.parse(arguments[0])),d.format.call(null,d.cache[arguments[0]],arguments)};return d.format=function(d,e){var f=1,g=d.length,h="",i,j=[],k,l,n,o,p,q;for(k=0;k<g;k++){h=a(d[k]);if(h==="string")j.push(d[k]);else if(h==="array"){n=d[k];if(n[2]){i=e[f];for(l=0;l<n[2].length;l++){if(!i.hasOwnProperty(n[2][l]))throw new Error(m('[_.sprintf] property "%s" does not exist',n[2][l]));i=i[n[2][l]]}}else n[1]?i=e[n[1]]:i=e[f++];if(/[^s]/.test(n[8])&&a(i)!="number")throw new Error(m("[_.sprintf] expecting number but found %s",a(i)));switch(n[8]){case"b":i=i.toString(2);break;case"c":i=b.fromCharCode(i);break;case"d":i=parseInt(i,10);break;case"e":i=n[7]?i.toExponential(n[7]):i.toExponential();break;case"f":i=n[7]?parseFloat(i).toFixed(n[7]):parseFloat(i);break;case"o":i=i.toString(8);break;case"s":i=(i=b(i))&&n[7]?i.substring(0,n[7]):i;break;case"u":i=Math.abs(i);break;case"x":i=i.toString(16);break;case"X":i=i.toString(16).toUpperCase()}i=/[def]/.test(n[8])&&n[3]&&i>=0?"+"+i:i,p=n[4]?n[4]=="0"?"0":n[4].charAt(1):" ",q=n[6]-b(i).length,o=n[6]?c(p,q):"",j.push(n[5]?i+o:o+i)}}return j.join("")},d.cache={},d.parse=function(a){var b=a,c=[],d=[],e=0;while(b){if((c=/^[^\x25]+/.exec(b))!==null)d.push(c[0]);else if((c=/^\x25{2}/.exec(b))!==null)d.push("%");else{if((c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b))===null)throw new Error("[_.sprintf] huh?");if(c[2]){e|=1;var f=[],g=c[2],h=[];if((h=/^([a-z_][a-z_\d]*)/i.exec(g))===null)throw new Error("[_.sprintf] huh?");f.push(h[1]);while((g=g.substring(h[0].length))!=="")if((h=/^\.([a-z_][a-z_\d]*)/i.exec(g))!==null)f.push(h[1]);else{if((h=/^\[(\d+)\]/.exec(g))===null)throw new Error("[_.sprintf] huh?");f.push(h[1])}c[2]=f}else e|=2;if(e===3)throw new Error("[_.sprintf] mixing positional and named placeholders is not (yet) supported");d.push(c)}b=b.substring(c[0].length)}return d},d}(),n={VERSION:"2.2.0rc",isBlank:function(a){return a==null&&(a=""),/^\s*$/.test(a)},stripTags:function(a){return a==null?"":b(a).replace(/<\/?[^>]+>/g,"")},capitalize:function(a){return a=a==null?"":b(a),a.charAt(0).toUpperCase()+a.slice(1)},chop:function(a,c){return a==null?[]:(a=b(a),c=~~c,c>0?a.match(new RegExp(".{1,"+c+"}","g")):[a])},clean:function(a){return n.strip(a).replace(/\s+/g," ")},count:function(a,c){return a==null||c==null?0:b(a).split(c).length-1},chars:function(a){return a==null?[]:b(a).split("")},swapCase:function(a){return a==null?"":b(a).replace(/\S/g,function(a){return a===a.toUpperCase()?a.toLowerCase():a.toUpperCase()})},escapeHTML:function(a){return a==null?"":b(a).replace(/[&<>"']/g,function(a){return"&"+k[a]+";"})},unescapeHTML:function(a){return a==null?"":b(a).replace(/\&([^;]+);/g,function(a,c){var d;return c in j?j[c]:(d=c.match(/^#x([\da-fA-F]+)$/))?b.fromCharCode(parseInt(d[1],16)):(d=c.match(/^#(\d+)$/))?b.fromCharCode(~~d[1]):a})},escapeRegExp:function(a){return a==null?"":b(a).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")},splice:function(a,b,c,d){var e=n.chars(a);return e.splice(~~b,~~c,d),e.join("")},insert:function(a,b,c){return n.splice(a,b,0,c)},include:function(a,c){return c===""?!0:a==null?!1:b(a).indexOf(c)!==-1},join:function(){var a=h.call(arguments),b=a.shift();return b==null&&(b=""),a.join(b)},lines:function(a){return a==null?[]:b(a).split("\n")},reverse:function(a){return n.chars(a).reverse().join("")},startsWith:function(a,c){return c===""?!0:a==null||c==null?!1:(a=b(a),c=b(c),a.length>=c.length&&a.slice(0,c.length)===c)},endsWith:function(a,c){return c===""?!0:a==null||c==null?!1:(a=b(a),c=b(c),a.length>=c.length&&a.slice(a.length-c.length)===c)},succ:function(a){return a==null?"":(a=b(a),a.slice(0,-1)+b.fromCharCode(a.charCodeAt(a.length-1)+1))},titleize:function(a){return a==null?"":b(a).replace(/(?:^|\s)\S/g,function(a){return a.toUpperCase()})},camelize:function(a){return n.trim(a).replace(/[-_\s]+(.)?/g,function(a,b){return b.toUpperCase()})},underscored:function(a){return n.trim(a).replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase()},dasherize:function(a){return n.trim(a).replace(/([A-Z])/g,"-$1").replace(/[-_\s]+/g,"-").toLowerCase()},classify:function(a){return n.titleize(b(a).replace(/_/g," ")).replace(/\s/g,"")},humanize:function(a){return n.capitalize(n.underscored(a).replace(/_id$/,"").replace(/_/g," "))},trim:function(a,d){return a==null?"":!d&&c?c.call(a):(d=i(d),b(a).replace(new RegExp("^"+d+"+|"+d+"+$","g"),""))},ltrim:function(a,c){return a==null?"":!c&&e?e.call(a):(c=i(c),b(a).replace(new RegExp("^"+c+"+"),""))},rtrim:function(a,c){return a==null?"":!c&&d?d.call(a):(c=i(c),b(a).replace(new RegExp(c+"+$"),""))},truncate:function(a,c,d){return a==null?"":(a=b(a),d=d||"...",c=~~c,a.length>c?a.slice(0,c)+d:a)},prune:function(a,c,d){if(a==null)return"";a=b(a),c=~~c,d=d!=null?b(d):"...";if(a.length<=c)return a;var e=function(a){return a.toUpperCase()!==a.toLowerCase()?"A":" "},f=a.slice(0,c+1).replace(/.(?=\W*\w*$)/g,e);return f.slice(f.length-2).match(/\w\w/)?f=f.replace(/\s*\S+$/,""):f=n.rtrim(f.slice(0,f.length-1)),(f+d).length>a.length?a:a.slice(0,f.length)+d},words:function(a,b){return n.isBlank(a)?[]:n.trim(a,b).split(b||/\s+/)},pad:function(a,c,d,e){a=a==null?"":b(a),c=~~c;var f=0;d?d.length>1&&(d=d.charAt(0)):d=" ";switch(e){case"right":return f=c-a.length,a+g(d,f);case"both":return f=c-a.length,g(d,Math.ceil(f/2))+a+g(d,Math.floor(f/2));default:return f=c-a.length,g(d,f)+a}},lpad:function(a,b,c){return n.pad(a,b,c)},rpad:function(a,b,c){return n.pad(a,b,c,"right")},lrpad:function(a,b,c){return n.pad(a,b,c,"both")},sprintf:m,vsprintf:function(a,b){return b.unshift(a),m.apply(null,b)},toNumber:function(a,c){if(a==null||a=="")return 0;a=b(a);var d=f(f(a).toFixed(~~c));return d===0&&!a.match(/^0+$/)?Number.NaN:d},numberFormat:function(a,b,c,d){if(isNaN(a)||a==null)return"";a=a.toFixed(~~b),d=d||",";var e=a.split("."),f=e[0],g=e[1]?(c||".")+e[1]:"";return f.replace(/(\d)(?=(?:\d{3})+$)/g,"$1"+d)+g},strRight:function(a,c){if(a==null)return"";a=b(a),c=c!=null?b(c):c;var d=c?a.indexOf(c):-1;return~d?a.slice(d+c.length,a.length):a},strRightBack:function(a,c){if(a==null)return"";a=b(a),c=c!=null?b(c):c;var d=c?a.lastIndexOf(c):-1;return~d?a.slice(d+c.length,a.length):a},strLeft:function(a,c){if(a==null)return"";a=b(a),c=c!=null?b(c):c;var d=c?a.indexOf(c):-1;return~d?a.slice(0,d):a},strLeftBack:function(a,b){if(a==null)return"";a+="",b=b!=null?""+b:b;var c=a.lastIndexOf(b);return~c?a.slice(0,c):a},toSentence:function(a,b,c,d){b=b||", ",c=c||" and ";var e=a.slice(),f=e.pop();return a.length>2&&d&&(c=n.rtrim(b)+c),e.length?e.join(b)+c+f:f},toSentenceSerial:function(){var a=h.call(arguments);return a[3]=!0,n.toSentence.apply(n,a)},slugify:function(a){if(a==null)return"";var c="ąàáäâãćęèéëêìíïîłńòóöôõùúüûñçżź",d="aaaaaaceeeeeiiiilnooooouuuunczz",e=new RegExp(i(c),"g");return a=b(a).toLowerCase().replace(e,function(a){var b=c.indexOf(a);return d.charAt(b)||"-"}),n.dasherize(a.replace(/[^\w\s-]/g,""))},surround:function(a,b){return[b,a,b].join("")},quote:function(a){return n.surround(a,'"')},exports:function(){var a={};for(var b in this){if(!this.hasOwnProperty(b)||b.match(/^(?:include|contains|reverse)$/))continue;a[b]=this[b]}return a},repeat:function(a,c,d){if(a==null)return"";c=~~c;if(d==null)return g(b(a),c);for(var e=[];c>0;e[--c]=a);return e.join(d)},levenshtein:function(a,c){if(a==null&&c==null)return 0;if(a==null)return b(c).length;if(c==null)return b(a).length;a=b(a),c=b(c);var d=[],e,f;for(var g=0;g<=c.length;g++)for(var h=0;h<=a.length;h++)g&&h?a.charAt(h-1)===c.charAt(g-1)?f=e:f=Math.min(d[h],d[h-1],e)+1:f=g+h,e=d[h],d[h]=f;return d.pop()}};n.strip=n.trim,n.lstrip=n.ltrim,n.rstrip=n.rtrim,n.center=n.lrpad,n.rjust=n.lpad,n.ljust=n.rpad,n.contains=n.include,n.q=n.quote,typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(module.exports=n),exports._s=n):typeof define=="function"&&define.amd?define("underscore.string",[],function(){return n}):(a._=a._||{},a._.string=a._.str=n)}(this,String);