1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 #pragma once
21 
22 /** \file
23  * \ingroup bli
24  * \brief A dynamically sized string ADT.
25  * \section aboutdynstr Dynamic String
26  * This ADT is designed purely for dynamic string creation
27  * through appending, not for general usage, the intent is
28  * to build up dynamic strings using a DynStr object, then
29  * convert it to a c-string and work with that.
30  */
31 
32 #include <stdarg.h>
33 
34 #include "BLI_compiler_attrs.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 struct DynStr;
41 
42 /** The abstract DynStr type */
43 typedef struct DynStr DynStr;
44 
45 DynStr *BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT;
46 DynStr *BLI_dynstr_new_memarena(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT;
47 
48 void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL();
49 void BLI_dynstr_nappend(DynStr *__restrict ds, const char *cstr, int len) ATTR_NONNULL();
50 
51 void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format, ...)
52     ATTR_PRINTF_FORMAT(2, 3) ATTR_NONNULL(1, 2);
53 void BLI_dynstr_vappendf(DynStr *__restrict ds, const char *__restrict format, va_list args)
54     ATTR_PRINTF_FORMAT(2, 0) ATTR_NONNULL(1, 2);
55 
56 int BLI_dynstr_get_len(DynStr *ds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
57 char *BLI_dynstr_get_cstring(DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
58 void BLI_dynstr_get_cstring_ex(DynStr *__restrict ds, char *__restrict rets) ATTR_NONNULL();
59 
60 void BLI_dynstr_clear(DynStr *ds) ATTR_NONNULL();
61 void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL();
62 
63 #ifdef __cplusplus
64 }
65 #endif
66