ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/atheme_string.h
Revision: 1.2
Committed: Sat Jul 21 01:29:07 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -2 lines
Log Message:
- moved to new documentation system
- fixed small build error

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2005 Atheme Development Group
3 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
4 pippijn 1.1 *
5     * String stuff.
6     *
7 pippijn 1.2 * $Id: atheme_string.h,v 1.1 2007-07-19 08:24:50 pippijn Exp $
8 pippijn 1.1 */
9    
10     #ifndef SVS_STRING_H
11     #define SVS_STRING_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     #ifndef HAVE_STRLCAT
22     extern size_t strlcat (char *dest, char const *src, size_t count);
23     #endif
24     #ifndef HAVE_STRLCPY
25     extern size_t strlcpy (char *dest, char const *src, size_t count);
26     #endif
27    
28     extern char const *strip (char *line);
29    
30     struct string
31     {
32     string (size_t size = 32)
33     : m_rep (new char[size]), pos (0), size (size)
34     {
35     }
36    
37     ~string ()
38     {
39     delete[] m_rep;
40     }
41    
42     void reset ()
43     {
44     m_rep[0] = '\0';
45     pos = 0;
46     }
47    
48     char const * const c_str () const
49     {
50     return m_rep;
51     }
52    
53     size_t length ()
54     {
55     return pos;
56     }
57    
58     string &operator = (char const *rhs)
59     {
60     reset ();
61     append (rhs, strlen (rhs));
62     return *this;
63     }
64    
65     int append (char const c);
66     int append_nonul (char c);
67     int append (char const *src, size_t size);
68     int append_nonul (char const *src, size_t size);
69    
70     int append_unguarded (char c);
71     int append_unguarded_nonul (char c);
72     int append_unguarded (char const *src, size_t size);
73     int append_unguarded_nonul (char const *src, size_t size);
74    
75     private:
76     char *m_rep;
77     size_t pos;
78     size_t size;
79     };
80    
81     #endif