Files CCore/inc/MakeString.h CCore/src/MakeString.cpp
MakeString is a simple string-building tool. It has an internal buffer and can append the content of this buffer with the overflow control.
template <ulen Len>
class MakeString : NoCopy
{
char buf[Len];
ulen len = 0 ;
bool overflow = false ;
public:
MakeString() {}
bool operator + () const { return !overflow; }
bool operator ! () const { return overflow; }
// add()
MakeString & add(StrLen str);
MakeString & add(const char *zstr);
MakeString & add(char ch);
MakeString & zero();
// multiadd
MakeString & add(NothingType) { return zero(); }
template <class T,class ... TT>
MakeString & add(T t,TT ... tt);
// get result
StrLen get() const { return StrLen(buf,len); }
const char * getZStr() const { return buf; }
};
The template parameter specifies the buffer capacity.
operator + returns true iff the buffer is not overflowed.
operator ! returns true iff the buffer is overflowed.
add() appends the arguments to the buffer and returns the reference to itself, so you may chain operations. If there is no enough room, the overflow flag is set. In this case the result is implementation-defined and should not be used. You may use the argument Null to do the zero() operation.
zero() appends the null character, but not advance the buffer position. If there is no enough room, the overflow flag is set. In this case the result is implementation-defined and should not be used.
get() returns the accumulated string as the StrLen object.
getZStr() returns the pointer to the buffer. You must use the zero() operation to make the string zero-terminated as the last operation.