/* * Copyright © 2005 Atheme Development Group * Rights to this code are as documented in doc/LICENSE. * * String stuff. * * $Id: atheme_string.h,v 1.1 2007/07/19 08:24:50 pippijn Exp $ */ #ifndef SVS_STRING_H #define SVS_STRING_H void assign (char *dst, char const *src, size_t maxlen); template inline void assign (char (&dst)[N], char const *src) { assign ((char *)&dst, src, N); } #ifndef HAVE_STRLCAT extern size_t strlcat (char *dest, char const *src, size_t count); #endif #ifndef HAVE_STRLCPY extern size_t strlcpy (char *dest, char const *src, size_t count); #endif extern char const *strip (char *line); struct string { string (size_t size = 32) : m_rep (new char[size]), pos (0), size (size) { } ~string () { delete[] m_rep; } void reset () { m_rep[0] = '\0'; pos = 0; } char const * const c_str () const { return m_rep; } size_t length () { return pos; } string &operator = (char const *rhs) { reset (); append (rhs, strlen (rhs)); return *this; } int append (char const c); int append_nonul (char c); int append (char const *src, size_t size); int append_nonul (char const *src, size_t size); int append_unguarded (char c); int append_unguarded_nonul (char c); int append_unguarded (char const *src, size_t size); int append_unguarded_nonul (char const *src, size_t size); private: char *m_rep; size_t pos; size_t size; }; #endif