//ַ͵չʵ
String.implement({

 //RegexʵtestĿݷʽ
 test: function(regex, params){
  return ((typeof regex == 'string') ? new RegExp(regex, params) : regex).test(this);
 },

 /*ַǷָӴ
   separatorԲƶŷָǷָ
   磺'jpg,gif,png'.contains(file_ext_name, ',')
 */
 contains: function(string, separator){
  return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1;
 },

 //ַеǰ󵼿հ
 trim: function(){
  return this.replace(/^\s+|\s+$/g, '');
 },

 //հ滻Ϊһո
 clean: function(){
  return this.replace(/\s+/g, ' ').trim();
 },

 //ַջ(ĸд)hyphenatecapitalizeϣͨڱ/
 camelCase: function(){
  return this.replace(/-\D/g, function(match){
   return match.charAt(1).toUpperCase();
  });
 },

 //ַӻ
 hyphenate: function(){
  return this.replace(/[A-Z]/g, function(match){
   return ('-' + match.charAt(0).toLowerCase());
  });
 },

 //ʹĸд
 capitalize: function(){
  return this.replace(/\b[a-z]/g, function(match){
   return match.toUpperCase();
  });
 },

 //תַ
 escapeRegExp: function(){
  return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
 },

 //parseIntĿݷʽ
 toInt: function(base){
  return parseInt(this, base || 10);
 },

 //toFloatĿݷʽ
 toFloat: function(){
  return parseFloat(this);
 },

 //ʮɫʾתΪRGBʾ
 hexToRgb: function(array){
  var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
  return (hex) ? hex.slice(1).hexToRgb(array) : null;
 },

 //ʮɫʾתΪRGBʾ
 rgbToHex: function(array){
  var rgb = this.match(/\d{1,3}/g);
  return (rgb) ? rgb.rgbToHex(array) : null;
 },

 //RGBɫʾתΪʮƱʾ
 stripscrpts: function(option){
  var scrpts = '';
  var text = this.replace(/<scrpt[^>]*>([\s\S]*?)<\/scrpt>/gi, function(){
   scrpts += arguments[1] + '\n';
   return '';
  });
  if (option === true) $exec(scrpts);
  else if ($type(option) == 'function') option(scrpts, text);
  return text;
 },

 /*
 formatһ滻ʽṩregexpƥԵӴӦobject滻
 磺
  var student = new Student('John', 'male', 17);
  alert('{name} is a {sex}, and {age} years old.'.substitute(student));
 ʾ
  John is a male, and 17 years old.
 ǲǺţ
 */
 substitute: function(object, regexp){
  return this.replace(regexp || (/\\?\{([^}]+)\}/g), function(match, name){
   if (match.charAt(0) == '\\') return match.slice(1);
   return (object[name] != undefined) ? object[name] : '';
  });
 }

});

