示例#1
0
/*int cStringList::FromMem(struct memfile &f) {
	int len;
	int bytes=0;
	bytes+=memread(f,&len,sizeof(int));
	cString temp="";
	char * tempchar=NULL;
	for(int i=0; i<len; i++) {
		tempchar=(char*)f.start;
		tempchar+=f.offset;
		temp=tempchar;
		
		bytes+=temp.Length()+1;
		f.offset+=temp.Length()+1;
		(*this)+=temp;
		temp="";
	}
	if((*this)[-1]=="" && Length()!=0) used--;
	return bytes;
}
*/
void cStringList::FromString(const cString &strng, cString delim) {
	if(delim.Length()==1) return FromString(strng,delim[0]);
	delete [] Array;
	Array=NULL;
	allocated=0;
	used=0;	
	Resize(500);
		
	cString substrng=delim;
	cString temp;
	used=1;
	for(int i=0; i<strng.Length(); ) FromString_innerloop(strng,delim,substrng, i);
}
示例#2
0
void cStringList::FromString_innerloop(const cString & strng, cString delim, cString &substrng, int & i) {
	int s=strng.Length();
	for(int j=0; j<delim.Length() && i+j<strng.Length(); j++) substrng[j]=strng[i+j];
	if(substrng!=delim && i<s) {
		if(used+1>allocated) {
			Resize(allocated+500);
		}
		Array[used-1]+=strng[i];
		i++;
	} else {
		used++;
		i+=substrng.Length();
	}
}
示例#3
0
bool cTimeAndDate::SetFromString(cString s) {

	//date string must be of the form mmddyy
	//but it can be in mddyy if m<10
	if(s.Length()<5) return false;

	if(s.Length()!=6) s="0"+s;
	
	
	cString m="  ",d="  ",y="  ";
	
	m[0]=s[0];
	m[1]=s[1];
	d[0]=s[2];
	d[1]=s[3];
	y[0]=s[4];
	y[1]=s[5];
	
	cTimeAndDate tempdate(m.AtoI(),d.AtoI(), y.AtoI()+2000);
	*this=tempdate;

	return true;
}
示例#4
0
void cStringList::FromString(const cString &mystring, char delim) {
	if(delim==' ') return FromStringWithSpaces(mystring);
	used=0;
	allocated=0;
	delete [] Array;
	Resize(mystring.Length());
	cString strng=mystring;
	strng+=delim;
	cString temp;
	for(int i=0; i<strng.Length(); i++) {
		if(strng[i]!=delim) {
			temp+=strng[i];
		} else {
			if(used+1>Length()) Resize(allocated+500);
			(*this)[used]=temp;
			used++;
			temp="";
		}
	}
	
}
示例#5
0
void cStringList::FromParagraph(const cString &mystring, int width) {
	
	if(mystring.Length()<width) {
		this->Resize(0);
		(*this)+=mystring;
	
	}
	//step one, create a list of words
	cStringList words;
	words.FromString(mystring," ");
	cStringList newlist;
	//step two, reconstruct a new list of multiple lines with multiple words,
	//conditions: each line may be no more than <width> chars long
	//each line must end in a space.
	cString linebuffer="";
	cString templinebuffer="";
	for(int i=0; i<words.Length(); i++) {
		if(linebuffer=="") {
			linebuffer=words[i];
			templinebuffer=linebuffer;
		} else  {
			templinebuffer=linebuffer+" "+words[i];
		}
		
		if(templinebuffer.Length()>width) {
			//cerr<<"adding "<<linebuffer<<endl;
			newlist+=linebuffer;
			linebuffer=words[i];
		}
		 else {
			//if(linebuffer=="") linebuffer=words[i];
			//else
			 linebuffer=templinebuffer;
		}
	}
	newlist+=linebuffer;
	(*this)=newlist;
}