1 /*
2  * dstring.h --
3  *
4  *	This file implements an abstract data type for dynamic strings.
5  *
6  *	Note: The behavior of the functions that modify the a dynamic
7  *	string is undefined if an argument strings points into the
8  *	dynamic string itself.
9  *
10  * Copyright (c) 2006 Juergen Schoenwaelder, International University Bremen.
11  *
12  * See the file "COPYING" for information on usage and redistribution
13  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14  *
15  * @(#) $Id: smilint.c 1867 2004-10-06 13:45:31Z strauss $
16  */
17 
18 #ifndef _DSTRING_H_
19 #define _DSTRING_H_
20 
21 #include <stdarg.h>
22 
23 #ifdef __GNUC__
24 # define inline /* extern */ static inline
25 #else
26 #ifdef HAVE_WIN_H
27 # define inline __inline
28 #endif
29 #endif
30 
31 struct dstring {
32     char   *str;
33     size_t len;
34 };
35 
36 typedef struct dstring dstring_t;
37 
38 inline char*
dstring_str(dstring_t * ds)39 dstring_str(dstring_t *ds)
40 {
41     return ds ? ds->str : NULL;
42 }
43 
44 inline size_t
dstring_len(dstring_t * ds)45 dstring_len(dstring_t *ds)
46 {
47     return ds ? ds->len : 0;
48 }
49 
50 extern dstring_t*
51 dstring_new(void);
52 
53 extern dstring_t*
54 dstring_delete(dstring_t *ds);
55 
56 extern dstring_t*
57 dstring_assign(dstring_t *ds, const char *s);
58 
59 extern dstring_t*
60 dstring_concat(dstring_t *ds, ...);
61 
62 extern dstring_t*
63 dstring_append(dstring_t *ds, const char *s);
64 
65 extern dstring_t*
66 dstring_append_char(dstring_t *ds, const char c);
67 
68 extern dstring_t*
69 dstring_append_printf(dstring_t *ds, const char *format, ...);
70 
71 extern dstring_t*
72 dstring_append_vprintf(dstring_t *ds, const char *format, va_list ap);
73 
74 extern dstring_t*
75 dstring_printf(dstring_t *ds, const char *format, ...);
76 
77 extern dstring_t*
78 dstring_vprintf(dstring_t *ds, const char *format, va_list ap);
79 
80 extern dstring_t*
81 dstring_truncate(dstring_t *ds, int len);
82 
83 extern dstring_t*
84 dstring_expand(dstring_t *ds, int len, char fill);
85 
86 #ifdef __GNUC__
87 #undef inline
88 #endif
89 
90 #endif
91