1 |
/* |
2 |
* Copyright © 2005 Atheme Development Group |
3 |
* Rights to this code are as documented in doc/LICENSE. |
4 |
* |
5 |
* String stuff. |
6 |
* |
7 |
* $Id: atheme_string.h,v 1.1 2007-07-11 11:04:40 pippijn Exp $ |
8 |
*/ |
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 |