ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/include/common/string.h
Revision: 1.1
Committed: Wed Jul 25 01:05:17 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
- moved to GPL
- added license information to files

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
3     * Rights to this code are as documented in doc/pod/gplicense.pod.
4     *
5     * Various string structures and functions.
6     *
7     * $Id: account.h,v 1.2 2007-07-21 01:29:07 pippijn Exp $
8     */
9    
10     #ifndef BASE64_H
11     #define BASE64_H
12    
13     void assign (char *dst, char const *src, size_t maxlen);
14    
15     template<size_t N>
16     inline void assign (char (&dst)[N], char const *src)
17     {
18     assign ((char *)&dst, src, N);
19     }
20    
21     struct string
22     {
23     string (size_t size = 32)
24     : m_rep (new char[size]), pos (0), size (size)
25     {
26     }
27    
28     ~string ()
29     {
30     delete[] m_rep;
31     }
32    
33     void reset ()
34     {
35     m_rep[0] = '\0';
36     pos = 0;
37     }
38    
39     char const * const c_str () const
40     {
41     return m_rep;
42     }
43    
44     size_t length ()
45     {
46     return pos;
47     }
48    
49     string &operator = (char const *rhs)
50     {
51     reset ();
52     append (rhs, strlen (rhs));
53     return *this;
54     }
55    
56     int append (char const c);
57     int append_nonul (char const c);
58     int append (char const * const src, size_t size);
59     int append_nonul (char const * const src, size_t size);
60    
61     int append_unguarded (char const c);
62     int append_unguarded_nonul (char const c);
63     int append_unguarded (char const * const src, size_t size);
64     int append_unguarded_nonul (char const * const src, size_t size);
65    
66     private:
67     char *m_rep;
68     size_t pos;
69     size_t size;
70     };
71    
72     #endif