define(["Ti/_","Ti/_/has","Ti/_/lang"],function(e,r,i){function a(e,r,i){var a,t=r-10;for(c(e.arg,"String")||(e.arg=""+e.arg);e.arg.length<t;)e.arg=e.rightJustify?e.arg+i:i+e.arg;a=r-e.arg.length,e.arg=e.rightJustify?e.arg+i.substring(0,a):i.substring(0,a)+e.arg}function t(e,r){a(e,i.val(r,e.precision),l)}function n(e,r){a(e,i.val(r,e.minWidth),f)}function s(e){e.maxWidth>=0&&e.arg.length>e.maxWidth?e.arg.substring(0,e.maxWidth):e.zeroPad?t(e,e.minWidth):n(e)}function o(e){var r=parseInt(e.arg);isFinite(r)||(p(!c(e.arg,"Number"),"Format argument '"+e.arg+"' not an integer; parseInt returned "+r),r=0),0>r&&(e.isUnsigned||10!=e.base)&&(r=4294967295+r+1),0>r?(e.arg=(-r).toString(e.base),t(e),e.arg="-"+e.arg):(e.arg=r.toString(e.base),r||e.precision?t(e):e.arg="",e.sign&&(e.arg=e.sign+e.arg)),16===e.base&&(e.alternative&&(e.arg="0x"+e.arg),e.arg=e.toUpper?e.arg.toUpperCase():e.arg.toLowerCase()),8===e.base&&e.alternative&&"0"!=e.arg.charAt(0)&&(e.arg="0"+e.arg)}function g(e){var r=parseFloat(e.arg);switch(isFinite(r)||(p(!c(e.arg,"Number"),"Format argument '"+e.arg+"' not a float; parseFloat returned "+r),r=0),e.specifier){case"e":e.arg=r.toExponential(e.precision);break;case"f":e.arg=r.toFixed(e.precision);break;case"g":e.arg=Math.abs(r)<1e-4?r.toExponential(e.precision>0?e.precision-1:e.precision):r.toPrecision(e.precision),e.alternative||(e.arg=e.arg.replace(/(\..*[^0])0*/,"$1"),e.arg=e.arg.replace(/\.0*e/,"e").replace(/\.0$/,""));break;default:throw new Error("Unexpected double notation '"+e.doubleNotation+"'")}e.arg=e.arg.replace(/e\+(\d)$/,"e+0$1").replace(/e\-(\d)$/,"e-0$1"),u&&(e.arg=e.arg.replace(/^\./,"0.")),e.alternative&&(e.arg=e.arg.replace(/^(\d+)$/,"$1."),e.arg=e.arg.replace(/^(\d+)e/,"$1.e")),r>=0&&e.sign&&(e.arg=e.sign+e.arg),e.arg=e.toUpper?e.arg.toUpperCase():e.arg.toLowerCase()}var p=e.assert,c=require.is,d=require.mix,u=r("opera"),l="0000000000",f="          ",h={b:{base:2,isInt:1},o:{base:8,isInt:1},x:{base:16,isInt:1},X:{extend:["x"],toUpper:1},d:{base:10,isInt:1},i:{extend:["d"]},u:{extend:["d"],isUnsigned:1},c:{setArg:function(e){if(!isNaN(e.arg)){var r=parseInt(e.arg);p(0>r||r>127,"Invalid character code passed to %c in sprintf"),e.arg=isNaN(r)?""+r:String.fromCharCode(r)}}},s:{setMaxWidth:function(e){e.maxWidth="."===e.period?e.precision:-1}},e:{isDouble:1},E:{extend:["e"],toUpper:1},f:{isDouble:1},F:{extend:["f"]},g:{isDouble:1},G:{extend:["g"],toUpper:1}};return String.format=function(e){for(var r,a,t,n,l=i.toArray(arguments),f=/\%(?:\(([\w_]+)\)|([1-9]\d*)\$)?([0 +\-\#]*)(\*|\d+)?(\.)?(\*|\d+)?[hlL]?([\%scdeEfFgGiouxX])/g,m=[],b=0,x=0,v=0,W="",I=["mapping","intmapping","flags","_minWidth","period","_precision","specifier"];a=f.exec(e);){if(n=e.slice(x,f.lastIndex-a[0].length),n.length&&m.push(n),u){for(t=a.slice(0);t.length<a.length;)t.push(null);a=t}r={},a.slice(1).concat(m.length).map(function(e,i){I[i]&&(r[I[i]]=e)}),m.push(r),r[0]&&b++,x=f.lastIndex}return n=e.slice(x),n.length&&m.push(n),l.shift(),p(!b||l.length,"Format has no mapped arguments"),m.forEach(function(r){var i,a,t,n={},u=h[r.specifier];if(c(r,"String"))W+=r;else{if(b?p(void 0===l[r.mapping],"Missing key "+r.mapping):(r.intmapping&&(v=parseInt(r.intmapping)-1),p(v<l.length,"Got "+l.length+" format arguments, insufficient for '"+e+"'")),r.arg=l[b?r.mapping:v++],!r.compiled){for(d(r,{compiled:1,sign:"",zeroPad:0,rightJustify:0,alternative:0,minWidth:0|r._minWidth,maxWidth:-1,toUpper:0,isUnsigned:0,isInt:0,isDouble:0,precision:"."===r.period?0|r._precision:1}),i=r.flags,a=i.length;a--;)switch(n[t=i.charAt(a)]=1,t){case" ":r.sign=" ";break;case"+":r.sign="+";break;case"0":r.zeroPad=!n["-"];break;case"-":r.rightJustify=1,r.zeroPad=0;break;case"#":r.alternative=1;break;default:throw new Error("Bad formatting flag '"+t+"'")}p(void 0!==u,"Unexpected specifier '"+r.specifier+"'"),u.extend&&(d(u,h[u.extend]),delete u.extend),d(r,u)}c(r.setArg,"Function")&&r.setArg(r),c(r.setMaxWidth,"Function")&&r.setMaxWidth(r),"*"===r._minWidth&&(p(b,"* width not supported in mapped formats"),p(isNaN(r.minWidth=parseInt(l[v++])),"The argument for * width at position "+v+" is not a number in "+this._format),r.minWidth<0&&(r.rightJustify=1,r.minWidth=-r.minWidth)),"*"===r._precision&&"."===r.period&&(p(b,"* precision not supported in mapped formats"),p(isNaN(r.precision=parseInt(l[v++])),"The argument for * precision at position "+v+" is not a number in "+this._format),r.precision<0&&(r.precision=1,r.period="")),r.isInt?("."===r.period&&(r.zeroPad=0),o(r)):r.isDouble&&("."!==r.period&&(r.precision=6),g(r)),s(r),W+=""+r.arg}}),W},{capitalize:function(e){return e=e||"",e.substring(0,1).toUpperCase()+e.substring(1)},trim:String.prototype.trim?function(e){return e.trim()}:function(e){return e.replace(/^\s\s*/,"").replace(/\s\s*$/,"")}}});