
unit string
{
	public const uint16 ID = 0;
	
	//[i] linkconst_int32_50 MaxLength;
	public const int32 MaxLength = 50;
	
	//[i] var_Cstring buffer;
	[uint8*MaxLength] buffer;
	
	//[i] var_int32 Length;
	public int32 Length;
	
	[uint8*11] number_buffer;
	
	int8 bchar;
	int8 number;

	//---------------------------------------------------
	//初始化
	//[i] function_void OS_init;
	public void OS_init()
	{
		Clear();
		bchar = ' ';
		number = 0;
	}
	//---------------------------------------------------
	//清空缓冲区
	//[i] function_void Clear;
	public void Clear()
	{
		Length = 0;
		buffer[0] = 0;
	}
	//---------------------------------------------------
	//判断字符串是否相等
	//[i] function_bool equal Cstring;
	public bool equal( [uint8*?] s )
	{
		int32 i = 0;
		while( s[i] != 0 ) {
			if( buffer[i] != s[i] ) {
				return false;
			}
			i + 1;
		}
		if( i != Length ) {
			return false;
		}
		return true;
	}
	//---------------------------------------------------
	//添加字符串
	//[i] function_void AddString Cstring;
	public void AddString( [uint8*?] s )
	{
		int32 i = 0;
		while( s[i] != 0 ) {
			buffer[Length] = s[i];
			Length + 1;
			i + 1;
		}
		buffer[Length] = 0;
	}
	//---------------------------------------------------
	//添加中文字符
	//[i] function_void AddCChar int32;
	public void AddCChar( int32 data0 )
	{
		if( data0 < 128 ) {
			buffer[Length] = (uint8)(uint16)(uint)data0;
			Length + 1;
		}
		else {
			uint16 d = (uint16)(uint)data0;
			buffer[Length] = d.0(uint8);
			Length + 1;
			buffer[Length] = d.8(uint8);
			Length + 1;
		}
		buffer[Length] = 0;
	}
	//---------------------------------------------------
	//添加数字
	//[i] function_void AddNumber int32;
	public void AddNumber( int32 data0 )
	{
		//计算正负数
		bool isNeg;
		uint32 data;
		if( data0 >= 0 ) {
			data = (uint)data0;
			isNeg = false;
		} else {
			data = (uint)-data0;
			isNeg = true;
		}
		//解析数字到缓冲区中
		int8 i = 0;
		forever {
			uint8 ch = '0' + (uint8)(uint16)(data % 10);
			number_buffer[i] = ch;
			i + 1;
			data / 10;
			if( data == 0 ) {
				break;
			}
		}
		//补齐数字格式
		if( number != 0 && i < number ) {
			int8 x = number - i;
			int8 y = i;
			loop( x ) {
				number_buffer[y] = (uint)bchar;
				y + 1;
			}
			i = number;
		}
		if( isNeg ) {
			number_buffer[i] = '-';
			i + 1;
		}
		do {
			i - 1;
			buffer[Length] = number_buffer[i];
			Length + 1;
		}
		while( i != 0 );
		
		buffer[Length] = 0;
	}
	//---------------------------------------------------
	//[i] function_void set_format int32 int32;
	public void set_format( int32 c, int32 n )
	{
		bchar = (int8)(int16)c;
		if( bchar < ' ' ) {
			bchar + '0';
		}
		number = (int8)(int16)n;
		if( number > 11 ) {
			number = 11;
		}
	}
	//---------------------------------------------------
	//[i] function_void clear_format;
	public void clear_format()
	{
		number = 0;
	}
}







