Debian Codegraph @

src/common/xstr.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2005 Dizzy
3 *
4 * xstr is a module trying to offer some high-level string functionality
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #ifndef INCLUDED_XSTR_TYPES
22 #define INCLUDED_XSTR_TYPES
23
24 namespace pvpgn
25 {
26
27 typedef struct {
28 unsigned alen, ulen;
29 char *str;
30 } t_xstr;
31
32 }
33
34 #define DECLARE_XSTR(var) \
35 t_xstr var = { 0, 0, NULL };
36
37 #endif /* INCLUDED_XSTR_TYPES */
38
39 #ifndef INCLUDED_XSTR_PROTOS
40 #define INCLUDED_XSTR_PROTOS
41
42 /* for NULL */
43 #include <cstddef>
44
45 namespace pvpgn
46 {
47
48 extern t_xstr* xstr_alloc(void);
49 extern void xstr_free(t_xstr*);
50 extern t_xstr* xstr_cpy_str(t_xstr* dst, const char* src);
51 extern t_xstr* xstr_cat_xstr(t_xstr* dst, const t_xstr* src);
52 extern t_xstr* xstr_cat_str(t_xstr* dst, const char* src);
53 extern t_xstr* xstr_ncat_str(t_xstr* dst, const char* src, int len);
54 extern t_xstr* xstr_cat_char(t_xstr* dst, const char ch);
55
56 static inline void xstr_init(t_xstr* xstr)
57 {
58 xstr->alen = xstr->ulen = 0;
59 xstr->str = NULL;
60 }
61
62 static inline const char* xstr_get_str(t_xstr* xstr)
63 {
64 if (xstr->alen && xstr->ulen) return xstr->str;
65 return NULL;
66 }
67
68 static inline unsigned xstr_get_len(t_xstr* xstr)
69 {
70 return xstr->alen ? xstr->ulen : 0;
71 }
72
73 static inline t_xstr* xstr_clear(t_xstr* xstr)
74 {
75 /* reset the string content, don't touch the allocation space */
76 xstr->ulen = 0;
77
78 return xstr;
79 }
80
81 }
82
83 #endif /* INCLUDED_STR_PROTOS */
84