﻿/*
* 字符串高级拼接类
*
* Copyright (c) 2008 kelezyb (eicesoft.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* $Date: 2008-1-15 10:25
* $Version: 0.0.1.1
*/


///cn: StringBuilder 字符串高级拼接类
///p:value 初始化数据
function StringBuilder(value)
{
        this._strArr = new Array();
        this._i = 0;

        ///fn:Init 初始化类
        ///p:value 需要加入的数据
        this.Init = function()
        {
                if(arguments[0])
                {
                        var value = arguments[0];
                        if (value.constructor == Array)
                        {
                                this._strArr = [].concat(value);
                                this._i = value.length;
                        }
                        else{
                                this.Append(value);
                        }
                }
        }

        ///fn:Append 加入一个数据
        ///p:str 需要加入的数据
        this.Append = function(str)
        {
                this._strArr[this._i] = str;
                this._i++;
        }

        ///fn:AppendLine 加入一个数据并追加换行符
        ///p:str 需要加入的数据
        this.AppendLine = function(str)
        {
                this._strArr[this._i] = str + '\n';
                this._i++;
        }

        ///fn:toString 返回所有字符串
        ///r:返回拼接之后所有字符串
        this.toString = function()
        {
                var seg = arguments[0]?arguments[0]:'';
                return this._strArr.join(seg);
        }

        ///fn:Remove 该序列的字符串
        ///p:index 序列号
        ///r:返回移除序列的字符串
        this.Remove = function(index)
        {
                if(index<=this._i++)
                {
                        var result = this._strArr[index];
                        this._strArr[index] = null;
                        return result;
                }
                else{
                        return null;
                }
        }

        ///fn:Length 字符串的字符长度
        ///r:返回总字符串的长度
        this.Length = function()
        {
                return this._strArr.join('').length;
        }
        this.Init(value);
}// JScript 文件


