#include "math.h"
#include "my_font.h"
#include "my_string.h"

static void reverse(char *str, int n) 
{
	int p = 0, q = n-1;
	char t;
	while (p < q) {
		t = str[p];
		str[p] = str[q];
		str[q] = t;
		p++;
		q--;
	}
}

void TMyString::Clear(void)
{
	Text[0] = '\0';
	Text[1] = '\0';
	Text[2] = '\0';
}

int TMyString::Insert(const char *source, int Pst)
{
	//dMYSTRING_LENGTH
	int i,x;
	unsigned int ilen, len;
	int sp;
	const char *aP = source;
	
	x = GetEndPst();
	if(x <= Pst){	
		AddOnStr(source);
		sp = GetEndPst();
		return sp;
	}
	
	for(i=0; i<dMYSTRING_LENGTH; i++)TmpChar[i] = 0;
	sp = GetLength();
	x =0;
	for(i=Pst+1; i<sp; i++){
		TmpChar[x] = Text[i];
		x++;
	}
	Text[Pst+1] = 0;
	AddOnStr(source);
	sp = GetEndPst();
	AddOnStr(TmpChar);
	Text[dMYSTRING_LENGTH - 1] = 0;
	
	return sp;
}

int TMyString::Insert(char *source, int Pst)
{
	//dMYSTRING_LENGTH
	int i,x;
	unsigned int ilen, len;
	int sp;
	char *aP = source;
	
	x = GetEndPst();
	if(x <= Pst){	
		AddOnStr(source);
		sp = GetEndPst();
		return sp;
	}
	
	for(i=0; i<dMYSTRING_LENGTH; i++)TmpChar[i] = 0;
	sp = GetLength();
	x =0;
	for(i=Pst+1; i<sp; i++){
		TmpChar[x] = Text[i];
		x++;
	}
	Text[Pst+1] = 0;
	AddOnStr(source);
	sp = GetEndPst();
	AddOnStr(TmpChar);
	Text[dMYSTRING_LENGTH - 1] = 0;
	
	return sp;
}

unsigned int  TMyString::Delete(int Pst)
{
	//dMYSTRING_LENGTH
	unsigned int i;
	unsigned int ilen;
	unsigned int sp;
	for(i=0; i<dMYSTRING_LENGTH; i++)TmpChar[i] = 0;
	sp = 0;
	for(i=Pst+1;  i < (dMYSTRING_LENGTH-1); i++){
		TmpChar[sp] = Text[i];
		if(TmpChar[sp] == 0)break;
		sp++;
	}
	if(Pst == -1){
		Clear();
		ilen = 0;
	}else
	if(Pst == 0){
		Clear();
		ilen = 1;
	}else{
		int PrvCharType = 0;
		for(i=0; i<=Pst; i++){
			if(Text[i] & 0x80){
				PrvCharType = 1;
				i++;
			}else{
				PrvCharType = 0;
			}
		}
		if( PrvCharType == 0){
			//this is AscII
			Text[Pst] = '\0';
			ilen = 1;
		}else{
			Text[Pst-1] = 0;
			Text[Pst] = 0;
			ilen = 2;
		}
	}
	AddOnStr(TmpChar);
	return ilen;
}

void TMyString::FromStr(const char *source)
{
	unsigned int i;
	unsigned int len;
	len = dMYSTRING_LENGTH -1;
	for(i=0; i<len; i++){
		Text[i]=source[i];
		if(source[i] == 0)break;
	}
	Text[len] = 0;
}

void TMyString::FromStr(char *source)
{
	unsigned int i;
	unsigned int len;
	len = dMYSTRING_LENGTH -1;
	for(i=0; i<len; i++){
		Text[i]=source[i];
		if(source[i] == 0)break;
	}
	Text[len] = 0;
}

void TMyString::FromStr(unsigned char *source)
{
	FromStr(source);
}

int TMyString::GetEndPst(void)
{
	unsigned int i;
	if(Text[0] == 0)return -1;
	for(i=1;i<dMYSTRING_LENGTH;i++){
		if(Text[i] == 0){
			return i-1;
		}
	}
	return -1;
}

int TMyString::GetLength(void)
{
	return GetEndPst() + 1;	
}

void TMyString::AddOnStr(const char *source)
{
	unsigned int i;
	unsigned int d=0;
	for(i=GetEndPst()+1; i<(dMYSTRING_LENGTH-1); i++){
		Text[i]=source[d];
		if(source[d] == 0)break;
		d++;
	}
	Text[dMYSTRING_LENGTH-1]=0;
}

void TMyString::AddOnStr( char *source)
{
	unsigned int i;
	unsigned int d=0;
	for(i=GetEndPst()+1; i<(dMYSTRING_LENGTH-1); i++){
		Text[i]=source[d];
		if(source[d] == 0)break;
		d++;
	}
	Text[dMYSTRING_LENGTH-1]=0;
}

void TMyString::ToStr(char *Dest, unsigned int len)
{
	unsigned int i;
	unsigned int limited;
	if(len<(dMYSTRING_LENGTH-1)) limited=len; else limited=dMYSTRING_LENGTH-1;
	i = sizeof(Text);
	if(i<limited) limited = i;
	for(i=0; i<limited; i++){
		Dest[i] = Text[i];
		if(Text[i] == 0)break;
	}
	Dest[i] = 0;
}

void TMyString::FromInt(int data)
{
	unsigned int i;
	unsigned int sig;
	unsigned int d,e;
	
	for(i=0;i<32;i++)TmpChar[i] = 0;
	
	if(data < 0){
		sig = 0;
		d = (unsigned int)(0 - data);
	}else{
		sig = 1;
		d = (unsigned int)data;
	}

	if(d == 0){
		Text[0] = '0';
		Text[1] = 0;
	}else{
		i = 0;
		while(d>0){
			e = d % 10;
			TmpChar[i] = e + '0';
			i++;
			d /= 10;
		}
		if(sig){
			d = i;
			while(i>0){
				Text[d-i] = TmpChar[i-1];
				i--;
			}
			Text[d] = 0;			
		}else{
			d = i;
			while(i>0){
				Text[d-i+1] = TmpChar[i-1];
				i--;
			}
			Text[0] = '-';
			Text[d+1] = 0;			
		}
	}	
}

void TMyString::FromUInt(unsigned int data)
{
	unsigned int i;
	unsigned int sig;
	unsigned int d,e;
	
	for(i=0;i<32;i++)TmpChar[i] = 0;
	
	if(data < 0){
		sig = 0;
		d = (unsigned int)(0 - data);
	}else{
		sig = 1;
		d = (unsigned int)data;
	}

	if(d == 0){
		Text[0] = '0';
		Text[1] = 0;
	}else{
		i = 0;
		while(d>0){
			e = d % 10;
			TmpChar[i] = e + '0';
			i++;
			d /= 10;
		}
		if(sig){
			d = i;
			while(i>0){
				Text[d-i] = TmpChar[i-1];
				i--;
			}
			Text[d] = 0;			
		}else{
			d = i;
			while(i>0){
				Text[d-i+1] = TmpChar[i-1];
				i--;
			}
			Text[0] = '-';
			Text[d+1] = 0;			
		}
	}	
}

void TMyString::sFromUInt(unsigned int data, unsigned char *Text)
{
	unsigned int i;
	unsigned int sig;
	unsigned int d,e;
	char aTmpChar[32];
	
	for(i=0;i<32;i++)aTmpChar[i] = 0;
	
	sig = 1;
	d = data;


	if(d == 0){
		Text[0] = '0';
		Text[1] = 0;
	}else{
		i = 0;
		while(d>0){
			e = d % 10;
			aTmpChar[i] = e + '0';
			i++;
			d /= 10;
		}
		if(sig){
			d = i;
			e = i;
			while(i>0){
				Text[e-i] = aTmpChar[i-1];
				i--;
			}
			Text[d] = 0;			
		}
	}	
}

void TMyString::FromUInt4Dg(unsigned int data)
{
	unsigned int d,e;
	
	d = data/1000;
	e = d % 10;
	Text[0] = e + '0';
	
	d = data/100;
	e = d % 10;
	Text[1] = e + '0';
	
	d = data/10;
	e = d % 10;
	Text[2] = e + '0';
	
	e = data % 10;
	Text[3] = e + '0';
	
	Text[4] = 0;
}

void TMyString::FromUInt6Dg(unsigned int data)
{
	unsigned int d,e;
	
	d = data/100000;
	e = d % 10;
	Text[0] = e + '0';
	
	d = data/10000;
	e = d % 10;
	Text[1] = e + '0';
	
	d = data/1000;
	e = d % 10;
	Text[2] = e + '0';
	
	d = data/100;
	e = d % 10;
	Text[3] = e + '0';
	
	d = data/10;
	e = d % 10;
	Text[4] = e + '0';
	
	e = data % 10;
	Text[5] = e + '0';
	
	Text[6] = 0;
}

void TMyString::FromUInt8Dg(unsigned int data)
{
	unsigned int d,e;
	
	d = data/10000000;
	e = d % 10;
	Text[0] = e + '0';
	
	d = data/1000000;
	e = d % 10;
	Text[1] = e + '0';
	
	d = data/100000;
	e = d % 10;
	Text[2] = e + '0';
	
	d = data/10000;
	e = d % 10;
	Text[3] = e + '0';
	
	d = data/1000;
	e = d % 10;
	Text[4] = e + '0';
	
	d = data/100;
	e = d % 10;
	Text[5] = e + '0';
	
	d = data/10;
	e = d % 10;
	Text[6] = e + '0';
	
	e = data % 10;
	Text[7] = e + '0';
	
	Text[8] = 0;
}


void TMyString::AddOnDgMax6(unsigned int data)
{
	unsigned int d,e,i,pst, IsFound;
	pst = GetEndPst() +1;
	if(pst > (dMYSTRING_LENGTH - 8))return;
	
	IsFound = 0;
	
	d = data/100000;
	e = d % 10;
	if(e>0){
		Text[pst] = e + '0';
		pst++;
		IsFound = 1;
	}
	
	d = data/10000;
	e = d % 10;
	if((e>0)||(IsFound)){
		Text[pst] = e + '0';
		pst++;
		IsFound = 1;
	}
	
	d = data/1000;
	e = d % 10;
	if((e>0)||(IsFound)){
		Text[pst] = e + '0';
		pst++;
		IsFound = 1;
	}
	
	d = data/100;
	e = d % 10;
	if((e>0)||(IsFound)){
		Text[pst] = e + '0';
		pst++;
		IsFound = 1;
	}
	
	d = data/10;
	e = d % 10;
	if((e>0)||(IsFound)){
		Text[pst] = e + '0';
		pst++;
		IsFound = 1;
	}
	
	e = data % 10;
	Text[pst++] = e + '0';
	
	Text[pst++] = 0;
	Text[pst++] = 0;	
}

void TMyString::AddOn8Dg(unsigned int data)
{
	unsigned int d,e,i,pst;
	pst = GetEndPst() +1;
	if(pst > (dMYSTRING_LENGTH - 10))return;
	
	d = data/10000000;
	e = d % 10;
	Text[pst] = e + '0';
	
	d = data/1000000;
	e = d % 10;
	Text[pst+1] = e + '0';
	
	d = data/100000;
	e = d % 10;
	Text[pst+2] = e + '0';
	
	d = data/10000;
	e = d % 10;
	Text[pst+3] = e + '0';
	
	d = data/1000;
	e = d % 10;
	Text[pst+4] = e + '0';
	
	d = data/100;
	e = d % 10;
	Text[pst+5] = e + '0';
	
	d = data/10;
	e = d % 10;
	Text[pst+6] = e + '0';
	
	e = data % 10;
	Text[pst+7] = e + '0';
	
	Text[pst+8] = 0;
}

void TMyString::AddOn6Dg(unsigned int data)
{
	unsigned int d,e,i,pst;
	pst = GetEndPst() +1;
	if(pst > (dMYSTRING_LENGTH - 8))return;
	
	d = data/100000;
	e = d % 10;
	Text[pst] = e + '0';
	
	d = data/10000;
	e = d % 10;
	Text[pst+1] = e + '0';
	
	d = data/1000;
	e = d % 10;
	Text[pst+2] = e + '0';
	
	d = data/100;
	e = d % 10;
	Text[pst+3] = e + '0';
	
	d = data/10;
	e = d % 10;
	Text[pst+4] = e + '0';
	
	e = data % 10;
	Text[pst+5] = e + '0';
	
	Text[pst+6] = 0;
}

void TMyString::AddOn4Dg(unsigned int data)
{
	unsigned int d,e,i,pst;
	pst = GetEndPst() +1;
	if(pst > (dMYSTRING_LENGTH - 6))return;
	
	d = data/1000;
	e = d % 10;
	Text[pst] = e + '0';
	
	d = data/100;
	e = d % 10;
	Text[pst+1] = e + '0';
	
	d = data/10;
	e = d % 10;
	Text[pst+2] = e + '0';
	
	e = data % 10;
	Text[pst+3] = e + '0';
	
	Text[pst+4] = 0;
}

void TMyString::FromUInt3Dg(unsigned int data)
{
	unsigned int i;
	unsigned int d,e;
	
	d = data/100;
	e = d % 10;
	Text[0] = e + '0';
	
	d = data/10;
	e = d % 10;
	Text[1] = e + '0';
	
	e = data % 10;
	Text[2] = e + '0';
	
	Text[3] = 0;
	Text[4] = 0;
}

void TMyString::AddOn3Dg(unsigned int data)
{
	unsigned int i,pst;
	unsigned int d,e;
	
	pst = GetEndPst() +1;
	if(pst > (dMYSTRING_LENGTH - 5))return;
	
	d = data/100;
	e = d % 10;
	Text[pst] = e + '0';
	
	d = data/10;
	e = d % 10;
	Text[pst+1] = e + '0';
	
	e = data % 10;
	Text[pst+2] = e + '0';
	
	Text[pst+3] = 0;
	Text[pst+4] = 0;
}

void TMyString::FromUInt2Dg(unsigned int data)
{
	unsigned int i;
	unsigned int d,e;
	
	d = data/10;
	Text[0] = d + '0';
	
	e = data % 10;
	Text[1] = e + '0';
	
	Text[2] = 0;
	Text[3] = 0;
}

void TMyString::AddOn2Dg(unsigned int data)
{
	unsigned int i,pst;
	unsigned int d,e;
	
	pst = GetEndPst() +1;
	if(pst > (dMYSTRING_LENGTH - 4))return;
	
	d = data/10;
	Text[pst] = d + '0';
	
	e = data % 10;
	Text[pst+1] = e + '0';
	
	Text[pst+2] = 0;
	Text[pst+3] = 0;
}
	
void TMyString::FormFloat(float fd)
{
	//unsigned int ava_bit = 0;
	float f = fd;
	unsigned int sig;
	signed int i = 0;
	signed int n = (int)f;
	
	if(f < 0){
		sig = 0;
		f *= -1;
	}else{
		sig = 1;
	}
	n = (unsigned int)f;
	f -= n;
	i = 0;
	do{
		Text[i++] = n % 10 + '0';
		n /= 10;
	}while(n > 0);
	if(0 == sig) Text[i++] = '-';

	reverse(Text , i);
	Text[i++] = '.';
	n = 0;
	do{
		int t = (int)(f * 10);
		Text[i++] = t + '0';
		f = f * 10 - t;
		n++;
	}while(f > 0 && n < 9);
	Text[i] = '\0';	
}

int TMyString::ToInteger(void)
{
	signed int Result;
	unsigned int i;
	unsigned int sig;

	if(Text[0] == '-'){
		sig = 0;
		i = 1;
	}else{
		sig = 1;
		i = 0;
	}
	Result = 0;
	while(1){
		if(Text[i] < '0' || Text[i] > '9'){
			if(Text[i] == 0) break;
			Result = 0;
			break;
		}else{	
			Result *= 10;
			Result += Text[i] - '0';
		}
		i++;
	}
	if(sig == 0) Result = 0 - Result;
	return Result;
	
}

float TMyString::ToFloat(void)
{
	float Result;

	float f;
	unsigned int i;
	unsigned int sig;
	unsigned int dot_found = 0;
	signed int Decimal_counts = 0;
	unsigned int valid_char_counts = 0;
	if(Text[0] == '-'){
		sig = 0;
		i = 1;
	}else{
		sig = 1;
		i = 0;
	}
	Result = 0;
	dot_found = 0;
	Decimal_counts = 0;
	while(1){
		if((Text[i] < '0' || Text[i] > '9') && (Text[i] != '.')){
			if(Text[i] != 0){
				Result = 0;
				break;
			}else{
				break;
			}
		}else{
			if(Text[i] == '.'){
				dot_found++;
			}else{
				if(Text[i] == '0'){
					if(valid_char_counts)valid_char_counts++;
				}else{
					valid_char_counts++;
				}	
				
				if(dot_found == 0){
					Result *= 10;
					Result += Text[i] - '0';
				}else if(dot_found == 1){
					Decimal_counts -=1;
					if(valid_char_counts > 12)break;
//					f = (Text[i] - '0') * pow(10,Decimal_counts);
					Result += f;
				}else{
					// error '0.0.' more then one dot found
					Result = 0;
					break;	
				}
			}
		}
		i++;
	}
	if(sig == 0) Result *= -1;
	return Result;
	
}


//Static function---------------->
void TMyString::sFromStr(char *source, char *dest)
{
	unsigned int i;
	unsigned int len;
	len = dMYSTRING_LENGTH -1;
	for(i=0; i<len; i++){
		dest[i]=source[i];
		if(dest[i] == 0){
			break;
		}
	}
}
void TMyString::sFromStr(const char *source, char *dest)
{
	unsigned int i;
	unsigned int len;
	len = dMYSTRING_LENGTH -1;
	for(i=0; i<len; i++){
		dest[i]=source[i];
		if(dest[i] == 0){
			break;
		}
	}
}

void TMyString::sFrom2Dg(unsigned int data, char *dest)
{
	unsigned int i;
	unsigned int d,e;
	d = data/10;
	e = d % 10;
	dest[0] = e + '0';
	
	e = data % 10;
	dest[1] = e + '0';
	
	dest[2] = 0;
	dest[3] = 0;
}

void TMyString::sFrom3Dg(unsigned int data, char *dest)
{
	unsigned int i;
	unsigned int d,e;
	d = data/100;
	e = d % 10;
	dest[0] = e + '0';
	
	d = data/10;
	e = d % 10;
	dest[1] = e + '0';
	
	e = data % 10;
	dest[2] = e + '0';
	
	dest[3] = 0;
	dest[4] = 0;
}

void TMyString::sFrom4Dg(unsigned int data, char *dest)
{
	unsigned int i;
	unsigned int d,e;
	
	d = data/1000;
	e = d % 10;
	dest[0] = e + '0';
	
	d = data/100;
	e = d % 10;
	dest[1] = e + '0';
	
	d = data/10;
	e = d % 10;
	dest[2] = e + '0';
	
	e = data % 10;
	dest[3] = e + '0';
	
	dest[4] = 0;
	dest[5] = 0;
}

void TMyString::sAddOnStr(const char *source, char *dest)
{
	unsigned int i;
	unsigned int d=0;
	int len = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)len++;
		else break;
	}	
	for(i=len; i<(dMYSTRING_LENGTH-1); i++){
		dest[i]=source[d];
		if(source[d] == 0)break;
		d++;
	}
}

void TMyString::sAddOnStr(unsigned char *source, char *dest)
{
	unsigned int i;
	unsigned int d=0;
	int len = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)len++;
		else break;
	}	
	for(i=len; i<(dMYSTRING_LENGTH-1); i++){
		dest[i]=source[d];
		if(source[d] == 0)break;
		d++;
	}
}

void TMyString::sAddOnChar(char aCr, char *dest)
{
	unsigned int i;
	unsigned int d=0;
	int len = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)len++;
		else break;
	}	
	for(i=len; i<(dMYSTRING_LENGTH-1); i++){
		dest[i]=aCr;
		dest[i+1]='\0';
		break;
	}
}

void TMyString::sAddOnStrL32(unsigned char *source, char *dest)
{
	unsigned int s;
	unsigned int i;
	unsigned int d=0;
	int len = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)len++;
		else break;
	}
	s = 0;
	for(i=len; i<(dMYSTRING_LENGTH-1); i++){
		if(s >= 32)break;
		dest[i]=source[d];
		if(source[d] == 0)break;
		d++;
		s++;
	}
	dest[i] = '\0';
}

void TMyString::sAddOnStrL32(char *source, char *dest)
{
	unsigned int s;
	unsigned int i;
	unsigned int d=0;
	int len = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)len++;
		else break;
	}
	s = 0;
	for(i=len; i<(dMYSTRING_LENGTH-1); i++){
		if(s >= 32)break;
		dest[i]=source[d];
		if(source[d] == 0)break;
		d++;
		s++;
	}
	dest[i] = '\0';
}

void TMyString::sAddOnDgMax6(unsigned int data, char *dest)
{
	unsigned int d,e,i,pst, IsFound;
	pst = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)pst++;
		else break;
	}
	pst;
	if(pst > (dMYSTRING_LENGTH - 8))return;
	
	IsFound = 0;
	
	d = data/100000;
	e = d % 10;
	if(e>0){
		dest[pst] = e + '0';
		pst++;
		IsFound = 1;
	}
	
	d = data/10000;
	e = d % 10;
	if((e>0)||(IsFound)){
		dest[pst] = e + '0';
		pst++;
		IsFound = 1;
	}
	
	d = data/1000;
	e = d % 10;
	if((e>0)||(IsFound)){
		dest[pst] = e + '0';
		pst++;
		IsFound = 1;
	}
	
	d = data/100;
	e = d % 10;
	if((e>0)||(IsFound)){
		dest[pst] = e + '0';
		pst++;
		IsFound = 1;
	}
	
	d = data/10;
	e = d % 10;
	if((e>0)||(IsFound)){
		dest[pst] = e + '0';
		pst++;
		IsFound = 1;
	}
	
	e = data % 10;
	dest[pst++] = e + '0';
	
	dest[pst++] = 0;
	dest[pst++] = 0;	
}

void TMyString::sAddOn8Dg(unsigned int data,  char *dest)
{
	unsigned int i;
	unsigned int d,e;
	int pst = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)pst++;
		else break;
	}
	pst;
	if(pst > (dMYSTRING_LENGTH - 10))return;
	
	d = data/10000000;
	e = d % 10;
	dest[pst] = e + '0';
	
	d = data/1000000;
	e = d % 10;
	dest[pst+1] = e + '0';
	
	d = data/100000;
	e = d % 10;
	dest[pst+2] = e + '0';
	
	d = data/10000;
	e = d % 10;
	dest[pst+3] = e + '0';
	
	d = data/1000;
	e = d % 10;
	dest[pst+4] = e + '0';
	
	d = data/100;
	e = d % 10;
	dest[pst+5] = e + '0';
	
	d = data/10;
	e = d % 10;
	dest[pst+6] = e + '0';
	
	e = data % 10;
	dest[pst+7] = e + '0';
	
	dest[pst+8] = 0;
}

void TMyString::sAddOn7Dg(unsigned int data,  char *dest)
{
	unsigned int i;
	unsigned int d,e;
	int pst = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)pst++;
		else break;
	}
	pst;
	if(pst > (dMYSTRING_LENGTH - 9))return;
	
	d = data/1000000;
	e = d % 10;
	dest[pst] = e + '0';
	
	d = data/100000;
	e = d % 10;
	dest[pst+1] = e + '0';
	
	d = data/10000;
	e = d % 10;
	dest[pst+2] = e + '0';
	
	d = data/1000;
	e = d % 10;
	dest[pst+3] = e + '0';
	
	d = data/100;
	e = d % 10;
	dest[pst+4] = e + '0';
	
	d = data/10;
	e = d % 10;
	dest[pst+5] = e + '0';
	
	e = data % 10;
	dest[pst+6] = e + '0';
	
	dest[pst+7] = 0;
}

void TMyString::sAddOn6Dg(unsigned int data,  char *dest)
{
	unsigned int i;
	unsigned int d,e;
	int pst = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)pst++;
		else break;
	}
	pst;
	if(pst > (dMYSTRING_LENGTH - 8))return;
	
	d = data/100000;
	e = d % 10;
	dest[pst] = e + '0';
	
	d = data/10000;
	e = d % 10;
	dest[pst+1] = e + '0';
	
	d = data/1000;
	e = d % 10;
	dest[pst+2] = e + '0';
	
	d = data/100;
	e = d % 10;
	dest[pst+3] = e + '0';
	
	d = data/10;
	e = d % 10;
	dest[pst+4] = e + '0';
	
	e = data % 10;
	dest[pst+5] = e + '0';
	
	dest[pst+6] = 0;
}


void TMyString::sAddOn5Dg(unsigned int data, char *dest)
{
	unsigned int i;
	unsigned int d,e;
	int pst = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)pst++;
		else break;
	}
	pst;
	if(pst > (dMYSTRING_LENGTH - 7))return;
	
	d = data/10000;
	e = d % 10;
	dest[pst] = e + '0';
	
	d = data/1000;
	e = d % 10;
	dest[pst+1] = e + '0';
	
	d = data/100;
	e = d % 10;
	dest[pst+2] = e + '0';
	
	d = data/10;
	e = d % 10;
	dest[pst+3] = e + '0';
	
	e = data % 10;
	dest[pst+4] = e + '0';
	
	dest[pst+5] = 0;
}


void TMyString::sAddOn4Dg(unsigned int data, char *dest)
{
	unsigned int i;
	unsigned int d,e;
	int pst = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)pst++;
		else break;
	}
	pst;
	if(pst > (dMYSTRING_LENGTH - 7))return;
	
	d = data/1000;
	e = d % 10;
	dest[pst] = e + '0';
	
	d = data/100;
	e = d % 10;
	dest[pst+1] = e + '0';
	
	d = data/10;
	e = d % 10;
	dest[pst+2] = e + '0';
	
	e = data % 10;
	dest[pst+3] = e + '0';
	
	dest[pst+4] = 0;
}


void TMyString::sAddOn3Dg(unsigned int data, char *dest)
{
	unsigned int i;
	unsigned int d,e;
	int pst = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)pst++;
		else break;
	}
	pst;
	if(pst > (dMYSTRING_LENGTH - 5))return;
	
	d = data/100;
	e = d % 10;
	dest[pst] = e + '0';
	
	d = data/10;
	e = d % 10;
	dest[pst+1] = e + '0';
	
	e = data % 10;
	dest[pst+2] = e + '0';
	
	dest[pst+3] = 0;
}

void TMyString::sAddOn1Dg(unsigned int data, char *dest)
{
	unsigned int i;
	unsigned int d,e;
	int pst = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)pst++;
		else break;
	}
	pst;
	if(pst > (dMYSTRING_LENGTH - 5))return;
	
	e = data % 10;
	dest[pst] = e + '0';
	
	dest[pst+1] = 0;
}

void TMyString::sAddOn_N_Dg(int aN, unsigned int d, char *dest)
{
	switch(aN){
		case 1: sAddOn1Dg(d,dest);break;
		case 2: sAddOn2Dg(d,dest);break;
		case 3: sAddOn3Dg(d,dest);break;
		case 4: sAddOn4Dg(d,dest);break;
		case 5: sAddOn5Dg(d,dest);break;
		case 6: sAddOn6Dg(d,dest);break;
		case 7: sAddOn7Dg(d,dest);break;
		case 8: sAddOn8Dg(d,dest);break;
	}
}

void TMyString::sAddOn2Dg(unsigned int data, char *dest)
{
	unsigned int i;
	unsigned int d,e;
	int pst = 0;
	for(i=0; i<(dMYSTRING_LENGTH-1); i++){
		if(dest[i] != 0)pst++;
		else break;
	}
	pst;
	if(pst > (dMYSTRING_LENGTH - 5))return;
	
	d = data/10;
	e = d % 10;
	dest[pst] = e + '0';
	
	e = data % 10;
	dest[pst+1] = e + '0';
	
	dest[pst+2] = 0;
}

int TMyString::sGetLen(char *source)
{
	int i,aLen;
	aLen = 0;
	for(i=0; i<1024; i++){
		if(*source !=0 ){
			aLen++;
		}else{
			break;
		}
		source++;
	}
	return aLen;
}

void TMyString::FillFixLen(unsigned int aLen)
{
	unsigned int len, i;
	len = sGetLen(Text);
	for(i=len; i< aLen; i++){
		Text[i] = ' ';
	}
	Text[aLen] = 0;
}

void TMyString::sFillFixLen(char *source, unsigned int aLen)
{
	unsigned int len, i;
	len = sGetLen(source);
	for(i=len; i< aLen; i++){
		source[i] = ' ';
	}
	source[aLen] = 0;
}


void TMyString::BrokeFixLen(int aLen)
{
	int i;
	int aFirst;
	int FoundCnStart;
	aFirst = 0;
	FoundCnStart = 0;
	for(i=0; i<aLen; i++){
		if(FoundCnStart == 1){
			FoundCnStart =2;
		}else{
			if((Text[i] & 0x80) != 0){
				FoundCnStart = 1;
				if(i == 31){
					Text[31] = 0;
				}
			}else{
				FoundCnStart = 0;
			}
		}
	}

	Text[aLen] = 0;
	if(FoundCnStart ==1){
		i = aLen-1;
		if(i>-1){
			Text[i] = 0;
		}
	}
}

void TMyString::sBrokeFixLen(char *source, int aLen)
{
	int i;
	int aFirst;
	int FoundCnStart;
	aFirst = 0;
	FoundCnStart = 0;
	for(i=0; i<aLen; i++){
		if(FoundCnStart == 1){
			FoundCnStart =2;
		}else{
			if((source[i] & 0x80) != 0){
				FoundCnStart = 1;
			}else{
				FoundCnStart = 0;
			}
		}
	}

	source[aLen] = 0;
	if(FoundCnStart ==1){
		i = aLen-1;
		if(i>-1){
			source[i] = 0;
		}
	}
}

void TMyString::sClear(char *dest)
{
	dest[0] = 0;
	dest[1] = 0;
	dest[2] = 0;
	dest[3] = 0;
}

int TMyString::sToInteger(char *Src)
{
	signed int Result;
	unsigned int i;
	unsigned int sig;

	if(Src[0] == '-'){
		sig = 0;
		i = 1;
	}else{
		sig = 1;
		i = 0;
	}
	Result = 0;
	while(1){
		if(Src[i] < '0' || Src[i] > '9'){
			if(Src[i] == 0) break;
			Result = 0;
			break;
		}else{	
			Result *= 10;
			Result += Src[i] - '0';
		}
		i++;
	}
	if(sig == 0) Result = 0 - Result;
	return Result;
}

int TMyString::sCompStr32Char(char *pStr1, char *pStr2)
{
	for(int i=0; i<32; i++){
		if(pStr1[i] != pStr2[i])return -1;
		if(pStr1[i] == 0){
			break;
		}
	}
	return 0;
}











