// Depends on Init.js
DARTY = DARTY || {};
DARTY.util = DARTY.util || {};
// <dependencies checking>
(function(){// Depends on Init.js
    var from = "DARTY.util.String";
    var libs = ["DARTY.util.Init"];    
	if (DARTY && DARTY.util && DARTY.util.required) {    
        DARTY.util.required(libs, from);
    }
    else {
      if(DARTY && DARTY.DEBUG) {	
        alert("Missing library : DARTY.util.Init in " + from);
      }  
    }
})();
// </dependencies checking>
DARTY.util.String = {};
// augmentation de la pseudo-classe String 
String.methods({
    endsWith: function(suffix){
        return this.length - suffix.length === this.lastIndexOf(suffix);
    },
    isBlank: function(){
        return null !== this.match(/^\s*$/);
    },
    startsWith: function(prefix){
        return 0 === this.indexOf(prefix);
    },
    trim: function(){
        return this.replace(/^\s+|\s+$/g, '');
    },
    stripHTML: function() {
       return this.replace(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>|&nbsp;/g, "");
    },
    supplant: function(o){
        return this.replace(/\{([^{}]*)\}/g, function(a, b){
            var r = eval('o.' + String(b));
            return typeof r === 'string' ? r : a;
        });
    },
    entityify: function(){
        return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
    }
});
