/*********************************************************************************************************************************************/
/**********************************************************Prototypes.js************************************************************************/
/**********************************************************************************************************************************************/
/** @file Prototypes.js
* @fileoverview String object prototype extensions
*/
/**@class String object prototype extensions
*/
var _spt = String.prototype;
/** Trim emulation
*@param {boolean} pass true if need ignore carriage simbol (false is default value)
*@param {boolean} pass true if need ignore inner White Space character (false is default value)
* @type string
*/
_spt.trim = function(blnIgnoreCarriage, blnIgnoreInnerWhiteSpace) {
var temp = this.replace(/^\s*/,"");
temp = temp.replace(/\s*$/,"");
blnIgnoreCarriage = blnIgnoreCarriage ? true : false;
blnIgnoreInnerWhiteSpace = blnIgnoreInnerWhiteSpace ? true : false;
if(blnIgnoreCarriage && blnIgnoreInnerWhiteSpace) {;}
else if(blnIgnoreCarriage&&!blnIgnoreInnerWhiteSpace) {
temp = temp.replace(/\t+/g," ");
temp = temp.replace(/ +/g," ");
}
else if(!blnIgnoreCarriage && blnIgnoreInnerWhiteSpace) {
temp=temp.replace(/(\n\r)+/g,"");
}
else if(!blnIgnoreCarriage && !blnIgnoreInnerWhiteSpace) {
temp=temp.replace(/\s+/g," ");
}
if(temp==" ") { temp=""; }
return temp;
};
/*_spt.match = function(strRegExp, strOption) {
var regEx = new RegExp(strRegExp, strOption ? strOption : "g");
return this.match(regEx);
};*/
/** remove sequence of characters from string
* @param {RegExp} strRegExp is regular expression
* @param {string} strOption is case sensitivity flag (default is 'g')
* @type string
*/
_spt.remove = function(strRegExp, strOption,str_replace) {
if(null==str_replace)
var str_replace = ""
var temp = this;
var regEx = new RegExp(strRegExp, strOption ? strOption : "g");
temp = temp.replace(regEx, str_replace);
return temp;
};
/**remove any tag from string;
* @type string
*/
_spt.removeTags = function() {
var regEx = /<[\/]?([a-zA-Z0-9]+)[^>^<]*>/ig; /*any tag*/
return this.replace(regEx,"");
}
/** test string, if exists regular expression seguence
* @param {RegExp} strRegExp is regular expression
* @param {string} strOption is case sensitivity flag (default is 'g')
* @type string
*/
_spt.test = function(strRegExp, strOption) {
var regEx = new RegExp(strRegExp, strOption ? strOption : "g");
return regEx.test(this);
};
/** strip xml tags
* @type string
*/
_spt.stripXml = function() {
var regEx = />([^a-zA-Z0-9]+)[^>^<]*</ig; /*any tag*/
return this.replace(regEx,"");
}
/** Decode xml string
* @type string
*/
_spt.xmlDecode=function()
{
//var strRegExp = "(.*)<(.*)>|(&lt)|(&amp)|(&quot)|($nbsp)|(&gt)|(&copy)";
var strRegExp = "(.*)<(.*)>|(&)|(" + String.fromCharCode(169) + ")|(" + String.fromCharCode(174) + ")|(" + String.fromCharCode(34) + ")";
var regEx = new RegExp(strRegExp,"g");
var temp = this.replace(/^\s*/,"");
temp = temp.replace(/\s*$/,"");
if(regEx.test(this)){
var left = /</g;
var right = />/g;
var Ampersand = /&/g;
var copyright = String.fromCharCode(169);
var reg = String.fromCharCode(174);
var quot = String.fromCharCode(34);
temp = temp.replace(left, "&lt;");
temp = temp.replace(right, "&gt;");
temp = temp.replace(copyright, "&copy;");
temp = temp.replace(reg, "&reg;");
temp = temp.replace(Ampersand, "&amp;");
temp = temp.replace(quot, "&quot;");
}
return temp;
};
/** Encode xml string
* @type string
*/
_spt.xmlEncode=function()
{
var strRegExp = "(.*)<(.*)>|(&lt;)|(&amp;)|(&quot;)|($nbsp;)|(&gt;)|(&copy)";
var regEx = new RegExp(strRegExp,"g");
var temp = this.replace(/^\s*/,"");
temp = temp.replace(/\s*$/,"");
if(regEx.test(this)){
var left = /&lt;/g;
var right = /&gt;/g;
var Ampersand = /&amp;/g;
var NoneBrackingSpace = /&nbsp;/g;
var quot = /&quot;/g;
var copyright = /&copy;/g;
var reg = /&reg;/g;
temp = temp.replace(left, "<");
temp = temp.replace(right, ">");
temp = temp.replace(copyright, String.fromCharCode(169));
temp = temp.replace(reg, String.fromCharCode(174));
temp = temp.replace(Ampersand, "&");
temp = temp.replace(NoneBrackingSpace, " ");
temp = temp.replace(quot,String.fromCharCode(34));
}
return temp;
};
/** get last xml element in xpath expression
*@type string
*/
_spt.getLastNodeName=function()
{
var temp = this;
var pos = temp.lastIndexOf("/")
return (pos!=-1)?temp.substr(pos+1):temp;
};
/** get rest string after passed sequence of characters
* @param {string} beginPath is sequence of chars
*@type string
*/
_spt.tail=function(beginPath)
{
var temp = this;
var pos = temp.indexOf(beginPath);
return (pos!=-1)?temp.substr(pos + 1):temp;
}

