- SString(const SString &source) : sizeGrowth(sizeGrowthDefault) {
- s = StringAllocate(source.s);
- sSize = sLen = (s) ? strlen(s) : 0;
+ /** Ownership of the buffer have been taken, so release it. */
+ void reset() {
+ s = 0;
+ sSize = 0;
+ }
+ /** Size of buffer. */
+ lenpos_t size() const {
+ return SContainer::size();
+ }
+};
+
+
+/**
+ * @brief A simple string class.
+ *
+ * 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 relies too heavily on C string
+ * functions to allow reliable manipulations of these strings, other than simple appends, etc.
+ */
+class SString : protected SContainer {
+ lenpos_t sLen; ///< The size of the string in s
+ lenpos_t sizeGrowth; ///< Minimum growth size when appending strings
+ enum { sizeGrowthDefault = 64 };
+
+ bool grow(lenpos_t lenNew);
+ SString &assign(const char *sOther, lenpos_t sSize_=measure_length);
+
+public:
+ SString() : sLen(0), sizeGrowth(sizeGrowthDefault) {}
+ SString(const SString &source) : SContainer(), sizeGrowth(sizeGrowthDefault) {
+ s = StringAllocate(source.s, source.sLen);
+ sSize = sLen = (s) ? source.sLen : 0;