/* * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in doc/pod/gplicense.pod. * * Various string structures and functions. * * $Id: string.h,v 1.1 2007/07/25 01:05:17 pippijn Exp $ */ #ifndef BASE64_H #define BASE64_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); } 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 const c); int append (char const * const src, size_t size); int append_nonul (char const * const src, size_t size); int append_unguarded (char const c); int append_unguarded_nonul (char const c); int append_unguarded (char const * const src, size_t size); int append_unguarded_nonul (char const * const src, size_t size); private: char *m_rep; size_t pos; size_t size; }; #endif