1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/**
* Copyright (C) Mellanox Technologies Ltd. 2019. ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/
/**
* Dynamic string buffer initializer. The backing storage should be released
* explicitly by calling @ref ucs_string_buffer_cleanup()
*/
/**
* Declare a string buffer which is using an existing string as backing store.
* Such string buffer does not allocate additional memory and does not have to
* be cleaned-up, and it can also be used to build a string onto existing
* C-string buffer passed as a function argument.
*
* @param _var String buffer variable name
* @param _buffer Buffer to use as backing store.
* @param _capacity Buffer capacity.
*
* Example:
*
* @code{.c}
* char * build_my_string(char *buffer, size_t max_length)
* {
* UCS_STRING_BUFFER_FIXED(strb, buffer, max_length);
* ucs_string_buffer_appendf(&strb, "%x%x", 57005, 48879);
* return buffer;
* }
* @endcode
*/
/**
* Declare a string buffer which is using a static array as backing store.
* Such string buffer does not allocate additional memory and does not have to
* be cleaned-up.
*
* @param _var String buffer variable name
* @param _buffer Buffer to use as backing store.
*
* Example:
*
* @code{.c}
* char buffer[100];
* UCS_STRING_BUFFER_FIXED(strb, buffer);
*
* ucs_string_buffer_appendf(&strb, "%x%x", 57005, 48879);
* @endcode
*/
/**
* String buffer - a dynamic NULL-terminated character buffer which can grow
* on demand.
*/
typedef struct ucs_string_buffer ucs_string_buffer_t;
/**
* Initialize a string buffer
*
* @param [out] strb String buffer to initialize.
*/
void ;
/**
* Initialize a string buffer with fixed-size buffer as backing storage.
*
* @param [out] strb String buffer to initialize.
* @param [in] buffer Buffer to use as backing storage.
* @param [in] capacity Buffer size.
*/
void ;
/**
* Cleanup a string buffer and release any memory associated with it.
*
* @param [out] strb String buffer to clean up.
*/
void ;
/**
* Reset a string buffer to initial empty state.
*
* @param [out] strb String buffer reset.
*/
void ;
/**
* Get the number of characters in a string buffer
*
* @param [out] strb Return the length of this string buffer.
*
* @return String buffer length.
*/
size_t ;
/**
* Append a formatted string to the string buffer.
*
* @param [inout] strb String buffer to append to.
* @param [in] fmt Format string.
*
* @note If the string cannot grow to the required length, only some of the
* characters would be appended.
*/
void ;
/**
* Append a hex dump to the string buffer.
*
* @param [inout] strb String buffer to append to.
* @param [in] data Raw data to hex-dump.
* @param [in] size Raw data size.
* @param [in] per_line Add a newline character after this number of bytes.
*
* @note If the string cannot grow to the required length, only some of the
* characters would be appended.
*/
void ;
/**
* Append a flag bitmask representation to the string buffer.
*
* @param [inout] strb String buffer to append to.
* @param [in] mask Append the representation of this mask value.
* @param [in] flag_names If non-NULL, use this array as flag names.
*/
void ;
/**
* Append an IO vector representation to the string buffer.
*
* @param [inout] strb String buffer to append to.
* @param [in] iov Pointer to an IO vector.
* @param [in] iovcnt Number of entries in the IO vector.
*/
void ;
/**
* Remove specific characters from the end of the string.
*
* @param [inout] strb String buffer remote characters from.
* @param [in] charset C-string with the set of characters to remove.
* If NULL, this function removes whitespace characters,
* as defined by isspace (3).
*
* This function removes the largest contiguous suffix from the input string
* 'strb', which consists entirely of characters in 'charset'.
*/
void ;
/**
* Return a temporary pointer to a C-style string which represents the string
* buffer. The returned string is valid only as long as no other operation is
* done on the string buffer (including append).
*
* @param [in] strb String buffer to convert to a C-style string.
*
* @return C-style string representing the data in the buffer.
*/
const char *;
/**
* Print the string buffer to a stream as multi-line text.
*
* @param [in] strb String buffer to print.
* @param [in] line_prefix Prefix to prepend to each output line.
* @param [in] stream Stream to print to.
*/
void ;
/**
* Return a pointer to a C-style string which represents the string buffer. The
* returned pointer should be freed with method which deallocates memory, e.g.
* ucs_free. There is no need to call ucs_string_buffer_cleanup in case of
* extracting memory using this method.
*
* @param [inout] strb String buffer to convert to a C-style string.
*
* @return C-style string representing the data in the buffer.
*/
char *;