#include <bufstr_t.hpp>
Based on str_t and safestr_t classes from libaga, of the same author, which were made back in 1999, but without C++ templating and exceptions.
Operations that would overflow will either throw the std::out_of_range error (if the THROW template parameter is true, which it is by default), or silently ignored.
See also http://www.codeproject.com/string/Allocdynstringsonstack.asp
Public Member Functions | |
| bufstr_t () | |
| This default constructor is sufficient to use the buffer. | |
| char * | c () |
| Access the buffer as null-terminated C string. | |
| char * | c_str () |
| Access the buffer as null-terminated C string. | |
| char * | end () const |
| Returns a pointer to the end of the contained string. | |
| std::pair< char const *, int > | pair () const |
| Access the buffer as std::pair. | |
| bufstr_t & | reset () |
| Set the length counter back to 0, so that the buffer can be reused. | |
| template<int C_SIZE, bool C_THROW> | |
| bufstr_t & | operator<< (const bufstr_t< C_SIZE, C_THROW > &ab) |
| Append another buffer. | |
| bufstr_t & | operator<< (std::pair< char const *, int > str) |
| Append a string whose length is known. | |
| bufstr_t & | operator<< (char const *cs) |
| Append a null-terminated character string. | |
| bufstr_t & | operator<< (const std::string &str) |
| Append a C++ string into the buffer. | |
| template<typename INT> | |
| bufstr_t & | appendInt (INT integer) |
| Append a signed integer to the buffer, converting it to decimal form. | |
| bufstr_t & | appendString (char const *str, int strLen) |
| Append a string whose length is known. | |
| bufstr_t & | appendString (char const *cs) |
| Append a null-terminated character string. | |
| bufstr_t & | appendString (const std::string &str) |
| Append a C++ string into the buffer. | |
| bufstr_t & | operator<< (int integer) |
| Append an int to the buffer, converting it to decimal form. | |
| bufstr_t & | operator<< (long long integer) |
| Append a long long to the buffer, converting it to decimal form. | |
| bufstr_t & | operator<< (char ch) |
| Append a single character to the buffer. | |
Public Attributes | |
| char | buf [SIZE+1] |
| The buffer (stack-allocated, if the containing instance is). | |
| int | len |
| The current length of the string. | |
|
|||||||||
|
Access the buffer as null-terminated C string. This method will terminate the buffer with zero. |
|
|||||||||
|
Access the buffer as null-terminated C string. This method will terminate the buffer with zero. |
|
|||||||||
|
Returns a pointer to the end of the contained string. bufstr.end() is a shorthand to (bufstr.buf + bufstr.len). |
|
|||||||||
|
Access the buffer as std::pair. The pair consists of a pointer to the beginning and the length of the contained string. |
|
|||||
|
The buffer (stack-allocated, if the containing instance is). The size of the buffer is SIZE + 1, so that we always have a space to zero-terminate the string. |
1.4.6