﻿/* Modify By XuJian 2007-11-02 
 出现和AJAXPro定义的StringBuilder冲突 所以将StringBuilder改名为SBuilder
*/
function SBuilder(value)
{
	this.strings = new Array("");
	this.append(value);
}

SBuilder.prototype.append = function(value)
{
	if (value) this.strings.push(value);
	return this;
}

SBuilder.prototype.toString = function()
{
	return this.strings.join("");
}

var CMFU_URL = "http://www.qidian.com";

/* 2007-10-26 14:20 Get String Lenth(include chinese character) */
function GetStringLength(strObj)
{
 return strObj.replace(/[^\x00-\xff]/g,"**").length;
}

/* 2007-11-28 */
//截取字符串 包含中文处理
function subString(str, len, ignoreDot)
{
	var newLength = 0;
	var newStr = "";
	var chineseRegex = /[^\x00-\xff]/g;
	var singleChar = "";
	str = str.replace('$l$','');
	str = str.replace('$h$','');
	var strLength = str.replace(chineseRegex,"**").length;
	for(var i = 0;i < strLength;i++)
	{
 singleChar = str.charAt(i).toString();
		if(singleChar.match(chineseRegex) != null)
		{
			newLength += 2;
		}	
		else
		{
			newLength++;
		}
		if(newLength > len)
		{
			break;
		}
		newStr += singleChar;
	}
	
	if(ignoreDot && strLength > len)
	{
	 newStr += "...";
	}
	return newStr;
}