﻿//**********************************************************************
//Array拡張
//**********************************************************************
//////// 指定位置のアイテムを除去 //////////////////////////////
Array.prototype.removeAt = function(idx) {
    if (idx < 0) {return;}
    this.splice(idx, 1);
}
//////// 指定位置にアイテムを挿入 //////////////////////////////
Array.prototype.insertAt = function(idx, value) {
    if (idx < 0) {return;}
    this.splice(idx, 0, value);
}

//**********************************************************************
//String拡張
//**********************************************************************
String.prototype.XMLEncode = function() {
    if (this == null) {return "";}
    if (this.length == 0) {return"";}

    var str = this;
    str = str.replace(/&/g, "&amp;");
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    str = str.replace(/"/g, "&quot;");
    str = str.replace(/'/g, "&apos;");
    
    return str;
}
String.prototype.XMLDecode = function() {
    if (this == null) {return "";}
    if (this.length == 0) {return"";}

    var str = this;
    str = str.replace(/&apos;/g, "'");
    str = str.replace(/&quot;/g, '"');
    str = str.replace(/&gt;/g, ">");
    str = str.replace(/&lt;/g, "<");
    str = str.replace(/&amp;/g, "&");
    
    return str;
}
String.prototype.HTMLEncode = function() {
    if (this == null) {return "";}
    if (this.length == 0) {return"";}

    var str = this;
    str = str.replace(/&/g, "&amp;");
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    str = str.replace(/"/g, "&quot;");
    str = str.replace(/'/g, "&apos;");
    str = str.replace(/\r\n/g, "\n").replace(/\n/g, "<br />");
    
    return str;
}
String.prototype.HTMLDecode = function() {
    if (this == null) {return "";}
    if (this.length == 0) {return"";}

    var str = this;
    str = str.replace(/\<br \/\>/g, "\n");
    str = str.replace(/&apos;/g, "'");
    str = str.replace(/&quot;/g, '"');
    str = str.replace(/&gt;/g, ">");
    str = str.replace(/&lt;/g, "<");
    str = str.replace(/&amp;/g, "&");
    
    return str;
}
//////// 指定長で文字列を切る //////////////////////////////
String.prototype.beginningSubString = function(len) {
    if (this == null) {return "";}
    if (this.length == 0) {return"";}
    if (this.length <= len ) { return this; }

    return this.substr(0, len) + "...";
}

