diff options
Diffstat (limited to 'include/SString.h')
-rw-r--r-- | include/SString.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/SString.h b/include/SString.h index 3efb84a03..960945dbc 100644 --- a/include/SString.h +++ b/include/SString.h @@ -109,6 +109,18 @@ public: const char *c_str() const { return s ? s : ""; } + /** Attach to a string allocated by means of StringAlloc(len). */ + SString &attach(char *s_, lenpos_t sLen_ = measure_length, lenpos_t sSize_ = measure_length) { + delete []s; + s = s_; + if (!s) { + sLen = sSize = 0; + } else { + sLen = (sLen_ == measure_length ? strlen(s) : sLen_); + sSize = (sSize_ == measure_length ? sLen + 1 : sSize_); + } + return *this; + } /** Give ownership of buffer to caller which must use delete[] to free buffer. */ char *detach() { char *sRet = s; @@ -175,6 +187,11 @@ public: static char *StringAllocate( const char *s, ///< The string to duplicate lenpos_t len=measure_length); ///< The length of memory to allocate. Optional. + /** + * Allocate uninitialized memory big enough to fit a string of the given length + * @return the pointer to the new string + */ + static char *StringAllocate(lenpos_t len); }; /** |