// Underscore.string
// (c) 2010 Esa-Matti Suuronen <esa-matti aet suuronen dot org>
// Underscore.strings is freely distributable under the terms of the MIT license.
// Documentation: https://github.com/edtsech/underscore.string
// Some code is borrowed from MooTools and Alexandru Marasteanu.
// Version 1.1.5
(function(){function e(a){if(a)return f.escapeRegExp(a);return"\\s"}function d(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var a=this,b=String.prototype.trim,c=function(a){return a*1||0},f={isBlank:function(a){return!!a.match(/^\s*$/)},capitalize:function(a){return a.charAt(0).toUpperCase()+a.substring(1).toLowerCase()},chop:function(a,b){b=b||a.length;var c=[];for(var d=0;d<a.length;)c.push(a.slice(d,d+b)),d=d+b;return c},clean:function(a){return f.strip(a.replace(/\s+/g," "))},count:function(a,b){var c=0,d;for(var e=0;e<a.length;)d=a.indexOf(b,e),d>=0&&c++,e=e+(d>=0?d:0)+b.length;return c},chars:function(a){return a.split("")},escapeHTML:function(a){return String(a||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")},unescapeHTML:function(a){return String(a||"").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&apos;/g,"'")},escapeRegExp:function(a){return String(a||"").replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1")},insert:function(a,b,c){var d=a.split("");d.splice(b,0,c);return d.join("")},includes:function(a,b){return a.indexOf(b)!==-1},join:function(a){a=String(a);var b="";for(var c=1;c<arguments.length;c+=1)b+=String(arguments[c]),c!==arguments.length-1&&(b+=a);return b},lines:function(a){return a.split("\n")},splice:function(a,b,c,d){var e=a.split("");e.splice(b,c,d);return e.join("")},startsWith:function(a,b){return a.length>=b.length&&a.substring(0,b.length)===b},endsWith:function(a,b){return a.length>=b.length&&a.substring(a.length-b.length)===b},succ:function(a){var b=a.split("");b.splice(a.length-1,1,String.fromCharCode(a.charCodeAt(a.length-1)+1));return b.join("")},titleize:function(a){var b=a.split(" "),c;for(var d=0;d<b.length;d++)c=b[d].split(""),typeof c[0]!="undefined"&&(c[0]=c[0].toUpperCase()),d+1===b.length?b[d]=c.join(""):b[d]=c.join("")+" ";return b.join("")},camelize:function(a){return f.trim(a).replace(/(\-|_|\s)+(.)?/g,function(a,b,c){return c?c.toUpperCase():""})},underscored:function(a){return f.trim(a).replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/\-|\s+/g,"_").toLowerCase()},dasherize:function(a){return f.trim(a).replace(/([a-z\d])([A-Z]+)/g,"$1-$2").replace(/^([A-Z]+)/,"-$1").replace(/\_|\s+/g,"-").toLowerCase()},trim:function(a,c){if(!c&&b)return b.call(a);c=e(c);return a.replace(new RegExp("^["+c+"]+|["+c+"]+$","g"),"")},ltrim:function(a,b){b=e(b);return a.replace(new RegExp("^["+b+"]+","g"),"")},rtrim:function(a,b){b=e(b);return a.replace(new RegExp("["+b+"]+$","g"),"")},truncate:function(a,b,c){c=c||"...";return a.slice(0,b)+c},words:function(a,b){b=b||" ";return a.split(b)},pad:function(a,b,c,e){var f="",g=0;c?c.length>1&&(c=c[0]):c=" ";switch(e){case"right":g=b-a.length,f=d(c,g),a=a+f;break;case"both":g=b-a.length,f={left:d(c,Math.ceil(g/2)),right:d(c,Math.floor(g/2))},a=f.left+a+f.right;break;default:g=b-a.length,f=d(c,g),a=f+a}return a},lpad:function(a,b,c){return f.pad(a,b,c)},rpad:function(a,b,c){return f.pad(a,b,c,"right")},lrpad:function(a,b,c){return f.pad(a,b,c,"both")},sprintf:function(){var a=0,b,c=arguments[a++],e=[],f,g,h,i,j="";while(c){if(f=/^[^\x25]+/.exec(c))e.push(f[0]);else if(f=/^\x25{2}/.exec(c))e.push("%");else{if(!(f=/^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(c)))throw"Huh ?!";if((b=arguments[f[1]||a++])==null||b==undefined)throw"Too few arguments.";if(/[^s]/.test(f[7])&&typeof b!="number")throw"Expecting number but found "+typeof b;switch(f[7]){case"b":b=b.toString(2);break;case"c":b=String.fromCharCode(b);break;case"d":b=parseInt(b);break;case"e":b=f[6]?b.toExponential(f[6]):b.toExponential();break;case"f":b=f[6]?parseFloat(b).toFixed(f[6]):parseFloat(b);break;case"o":b=b.toString(8);break;case"s":b=(b=String(b))&&f[6]?b.substring(0,f[6]):b;break;case"u":b=Math.abs(b);break;case"x":b=b.toString(16);break;case"X":b=b.toString(16).toUpperCase()}b=/[def]/.test(f[7])&&f[2]&&b>=0?"+"+b:b,h=f[3]?f[3]=="0"?"0":f[3].charAt(1):" ",i=f[5]-String(b).length-j.length,g=f[5]?d(h,i):"",e.push(j+(f[4]?b+g:g+b))}c=c.substring(f[0].length)}return e.join("")},toNumber:function(a,b){return c(c(a).toFixed(c(b)))},strRight:function(a,b){var c=b?a.indexOf(b):-1;return c!=-1?a.slice(c+b.length,a.length):a},strRightBack:function(a,b){var c=b?a.lastIndexOf(b):-1;return c!=-1?a.slice(c+b.length,a.length):a},strLeft:function(a,b){var c=b?a.indexOf(b):-1;return c!=-1?a.slice(0,c):a},strLeftBack:function(a,b){var c=a.lastIndexOf(b);return c!=-1?a.slice(0,c):a}};f.strip=f.trim,f.lstrip=f.ltrim,f.rstrip=f.rtrim,f.center=f.lrpad,f.ljust=f.lpad,f.rjust=f.rpad,typeof window=="undefined"&&typeof module!="undefined"?module.exports=f:typeof a._!="undefined"?a._.mixin(f):a._=f})()
