diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/PropSet.h | 74 | 
1 files changed, 53 insertions, 21 deletions
| diff --git a/include/PropSet.h b/include/PropSet.h index 2aefcdbd8..a5473915c 100644 --- a/include/PropSet.h +++ b/include/PropSet.h @@ -14,42 +14,76 @@ bool EqualCaseInsensitive(const char *a, const char *b);  inline char *StringDup(const char *s, int len=-1) {  	if (!s)  		return 0; -    if (len == -1) -        len = strlen(s); +	if (len == -1) +		len = strlen(s);  	char *sNew = new char[len + 1]; -    if (sNew) { +	if (sNew) {  		strncpy(sNew, s, len); -        sNew[len] = '\0'; -    } +		sNew[len] = '\0'; +	}  	return sNew;  }  class SString {  	char *s; +	int ssize;  public: +	typedef const char* const_iterator; +	typedef int size_type; +	static size_type npos; +	const char* begin(void) const { +		return s; +	} +	const char* end(void) const { +		return &s[ssize]; +	} +	size_type size(void) const { +		if (s) +			return ssize; +		else +			return 0; +	} +	SString &assign(const char* sother, int size_ = -1) { +		char *t = s; +		s = StringDup(sother,size_); +		ssize = (s) ? strlen(s) : 0; +		delete []t; +		return *this; +	} +	SString &assign(const SString& sother, int size_ = -1) { +		return assign(sother.s,size_); +	} +	SString &assign(const_iterator ibeg, const_iterator iend) { +		return assign(ibeg,iend - ibeg); +	}  	SString() {  		s = 0; +		ssize = 0;  	}  	SString(const SString &source) {  		s = StringDup(source.s); +		ssize = (s) ? strlen(s) : 0;  	}  	SString(const char *s_) {  		s = StringDup(s_); +		ssize = (s) ? strlen(s) : 0;  	}  	SString(int i) {  		char number[100];  		sprintf(number, "%0d", i); -		//itoa(i, number, 10);  		s = StringDup(number); +		ssize = (s) ? strlen(s) : 0;  	}  	~SString() {  		delete []s;  		s = 0; +		ssize = 0;  	}  	SString &operator=(const SString &source) {  		if (this != &source) {  			delete []s;  			s = StringDup(source.s); +			ssize = (s) ? strlen(s) : 0;  		}  		return *this;  	} @@ -92,29 +126,27 @@ public:  			return '\0';  	}  	SString &operator +=(const char *sother) { -		int len = length(); -		int lenOther = strlen(sother); -		char *sNew = new char[len + lenOther + 1]; -		if (sNew) { -			if (s) -				memcpy(sNew, s, len); -			memcpy(sNew + len, sother, lenOther); -			sNew[len + lenOther] = '\0'; -			delete []s; -			s = sNew; -		} -		return *this; +		return append(sother,-1); +	} +	SString &operator +=(const SString &sother) { +		return append(sother.s,sother.ssize);  	}  	SString &operator +=(char ch) { +		return append(&ch,1); +	} +	SString &append(const char* sother, int lenOther) {  		int len = length(); -		char *sNew = new char[len + 1 + 1]; +		if(lenOther < 0)  +			lenOther = strlen(sother); +		char *sNew = new char[len + lenOther + 1];  		if (sNew) {  			if (s)  				memcpy(sNew, s, len); -			sNew[len] = ch; -			sNew[len + 1] = '\0'; +			strncpy(&sNew[len], sother, lenOther); +			sNew[len + lenOther] = '\0';  			delete []s;  			s = sNew; +			ssize = (s) ? strlen(s) : 0;  		}  		return *this;  	} | 
