/**
 *  $Id: stringextensions.js 141 2006-12-07 15:25:39Z wingedfox $
 *  $HeadURL: https://svn.debugger.ru/repos/jslibs/BrowserExtensions/tags/BrowserExtensions.001/stringextensions.js $
 * 
 *  @author Ildar Shaimordanov
 *  @author Ilya Lebedev
 *  @license LGPL
 *  @version $Rev: 141 $
 */
String.prototype.ltrim=function(i){i=new RegExp("^("+(i?RegExp.escape(i):"\\s")+")+");return this.replace(i,"");};String.prototype.rtrim=function(i){i=new RegExp("("+(i?RegExp.escape(i):"\\s")+")+$");return this.replace(i,"");};String.prototype.trim=function(i){i=new RegExp("^("+(i?RegExp.escape(i):"\\s")+")+|("+(i?RegExp.escape(i):"\\s")+")+$","g");return this.replace(i,"");};String.prototype.dup=function(){var i=this.valueOf();return[i,i].join("");};String.prototype.repeat=function(i){if(isNaN(i=parseInt(i))||i<0)return"";return Array(i+1).join(this.valueOf());};String.prototype.padding=function(i,I){var l=this.valueOf();i=parseInt(i);if(!i)return l;if(isUndefined(I))I=" ";var o=String(I).charAt(0).repeat(Math.abs(i)-this.length);return(i<0)?o+l:l+o};String.prototype.padLeft=function(i,I){return this.padding(-Math.abs(i),I);};String.prototype.padRight=function(i,I){return this.padding(Math.abs(i),I);};String.prototype.sprintf=function(){var i=isArray(arguments[0])?arguments[0]:arguments,I=0,l=this.replace(/%%/g,"\0\0"),o= /%((?:\d+\$)?)((?:[-0+# ])?)((?:\d+|\*(?:\d+\$)?)?)((?:.(?:\d+|\*(?:\d+\$)?))?)([bcdeEfosuxX])/g;l=l.replace(o,function(){var O=arguments,Q=false,_;if(!isUndefined(O[3])&&O[3].indexOf("*")==0){O[3]=parseInt(O[3].replace(/\D/g,""));if(isNaN(O[3])){O[3]=i[I];I++}else{O[3]=i[O[3]]}}if(""!=O[4]){if(O[4].indexOf("*")==1){O[4]=parseInt(O[4].replace(/\D/g,""));if(isNaN(O[4])){O[4]=i[I];I++}else{O[4]=i[O[4]]}}else{O[4]=O[4].replace(/\D/,"")}O[4]=Math.abs(O[4]);}O[1]=parseInt(O[1]);var _;if(isNumeric(O[1])){_=i[O[1]]}else{_=i[I];I++}switch(O[5]){case"b":if(_<0)_=0x10000000000000000+parseInt(_);_=Number(_).bin(O[4]);if(O[4])_=_.substr(0,O[4]);if(O[2]=='#')_='0b'+_;break;case"c":_=String.fromCharCode(_);break;case"u":_=Math.abs(_);case"d":_=Math.round(_);if(_<0){_="-"+Math.abs(_).dec(O[4]);}else{_=Number(_).dec(O[4]);Q=(O[2]==' '||O[2]=='+');}break;case"e":case"E":if(_>0){Q=(O[2]==' '||O[2]=='+');}_=Number(_).toExponential(O[4]?O[4]:6);if(O[5]=='E')_=_.toUpperCase();break;case"f":if(_>0){Q=(O[2]==' '||O[2]=='+');}_=Number(_).toFixed(isNumeric(O[4])?O[4]:6);break;case"o":if(_<0)_=0x10000000000000000+parseInt(_);_=Number(_).toString(8);if(O[4])_=_.substr(0,O[4]);if(O[2]=='#'&&_!=0)_='0'+_;break;case"s":_=String(_);if(O[4])_=_.substr(0,O[4]);break;case"x":case"X":if(_<0)_=0x10000000000000000+parseInt(_);_=Number(_).hex(-O[4]);if(O[4])_=_.substr(0,O[4]);if(O[2]=='#')_='0x'+_;if(O[5]=='X')_=_.toUpperCase();break}if(Q)_=O[2]+_;if(O[3])_=(O[2]=='-'||O[3]<0)?_.padRight(O[3]):_.padLeft(O[3],O[2]=='0'?0:" ");return _});return l.replace(/\0\0/g,"%");};
