1 /* String descriptors, with out-of-memory checking.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation, either version 3 of the License,
7 or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2023. */
19 #ifndef _XSTRING_DESC_H
20 #define _XSTRING_DESC_H 1
22 /* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */
23 #if !_GL_CONFIG_H_INCLUDED
24 #error "Please include config.h first."
28 #include "string-desc.h"
32 _GL_INLINE_HEADER_BEGIN
33 #ifndef GL_XSTRING_DESC_INLINE
34 # define GL_XSTRING_DESC_INLINE _GL_INLINE
42 /* ==== Memory-allocating operations on string descriptors ==== */
44 /* Return a string of length N, with uninitialized contents. */
45 #if 0 /* Defined inline below. */
46 extern string_desc_t
xstring_desc_new (idx_t n
);
49 /* Return a string of length N, filled with C. */
50 #if 0 /* Defined inline below. */
51 extern string_desc_t
xstring_desc_new_filled (idx_t n
, char c
);
54 /* Return a copy of string S. */
55 #if 0 /* Defined inline below. */
56 extern string_desc_t
xstring_desc_copy (string_desc_t s
);
59 /* Return the concatenation of N strings. N must be > 0. */
60 extern string_desc_t
xstring_desc_concat (idx_t n
, string_desc_t string1
, ...);
62 /* Construct and return a copy of string S, as a NUL-terminated C string. */
63 #if 0 /* Defined inline below. */
64 extern char * xstring_desc_c (string_desc_t s
) _GL_ATTRIBUTE_DEALLOC_FREE
;
68 /* ==== Inline function definitions ==== */
70 GL_XSTRING_DESC_INLINE string_desc_t
71 xstring_desc_new (idx_t n
)
74 if (string_desc_new (&result
, n
) < 0)
79 GL_XSTRING_DESC_INLINE string_desc_t
80 xstring_desc_new_filled (idx_t n
, char c
)
83 if (string_desc_new_filled (&result
, n
, c
) < 0)
88 GL_XSTRING_DESC_INLINE string_desc_t
89 xstring_desc_copy (string_desc_t s
)
92 if (string_desc_copy (&result
, s
) < 0)
97 GL_XSTRING_DESC_INLINE
98 _GL_ATTRIBUTE_DEALLOC_FREE
100 xstring_desc_c (string_desc_t s
)
102 char *result
= string_desc_c (s
);
113 _GL_INLINE_HEADER_END
116 #endif /* _XSTRING_DESC_H */