diff options
| -rw-r--r-- | include/SString.h | 19 | 
1 files changed, 13 insertions, 6 deletions
| diff --git a/include/SString.h b/include/SString.h index df7fd43b5..eacfef35b 100644 --- a/include/SString.h +++ b/include/SString.h @@ -22,8 +22,8 @@ bool EqualCaseInsensitive(const char *a, const char *b);   *   * Hold the length of the string for quick operations,   * can have a buffer bigger than the string to avoid too many memory allocations and copies. - * May have embedded zeroes as a result of @a substitute, but rely too heavily on C string - * functions to allow reliable manipulations of these strings. + * May have embedded zeroes as a result of @a substitute, but relies too heavily on C string + * functions to allow reliable manipulations of these strings, other than simple appends, etc.   **/  class SString {  public: @@ -63,7 +63,7 @@ private:  		}  		if (sSize > 0 && sSize_ <= sSize) {	// Does not allocate new buffer if the current is big enough  			if (s && sSize_) { -				strncpy(s, sOther, sSize_); +				memcpy(s, sOther, sSize_);  			}  			s[sSize_] = '\0';  			sLen = sSize_; @@ -206,7 +206,7 @@ public:  				s[sLen] = sep;  				sLen++;  			} -			strncpy(&s[sLen], sOther, sLenOther); +			memcpy(&s[sLen], sOther, sLenOther);  			sLen += sLenOther;  			s[sLen] = '\0';  		} @@ -259,6 +259,13 @@ public:  			sLen -= len;  		}  	} +	SString &change(lenpos_t pos, char ch) { +		if (pos >= sLen) {					// character changed must be in string bounds +			return *this; +		} +		*(s + pos) = ch; +		return *this; +	}  	/** Read an integral numeric value from the string. */  	int value() const {  		if (s) @@ -266,7 +273,7 @@ public:  		else  			return 0;  	} -	int search(const char *sFind, lenpos_t start=0) { +	int search(const char *sFind, lenpos_t start=0) const {  		if (start < sLen) {  			const char *sFound = strstr(s + start, sFind);  			if (sFound) { @@ -325,7 +332,7 @@ public:  		}  		char *sNew = new char[len + 1];  		if (sNew) { -			strncpy(sNew, s, len); +			memcpy(sNew, s, len);  			sNew[len] = '\0';  		}  		return sNew; | 
