Blender V4.3
BLI_string_utils.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11#include <stdarg.h>
12#include <string>
13
14#include "BLI_compiler_attrs.h"
15#include "BLI_function_ref.hh"
16#include "BLI_string_ref.hh"
17#include "BLI_utildefines.h"
18
19struct ListBase;
20
21using UniquenameCheckCallback = bool (*)(void *arg, const char *name);
22
23/* ------------------------------------------------------------------------- */
40char *BLI_string_replaceN(const char *__restrict str,
41 const char *__restrict substr_old,
42 const char *__restrict substr_new) ATTR_WARN_UNUSED_RESULT
44
52void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1);
53
61bool BLI_string_replace_table_exact(char *string,
62 size_t string_len,
63 const char *replace_table[][2],
64 int replace_table_len);
65
73 char *string, size_t string_maxncpy, int src_beg, int src_end, const char *dst);
74
77/* ------------------------------------------------------------------------- */
95size_t BLI_string_split_name_number(const char *name, char delim, char *r_name_left, int *r_number)
96 ATTR_NONNULL(1, 3, 4);
97bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(1);
98
103void BLI_string_split_suffix(const char *string, size_t string_maxlen, char *r_body, char *r_suf)
104 ATTR_NONNULL(1, 3, 4);
108void BLI_string_split_prefix(const char *string, size_t string_maxlen, char *r_pre, char *r_body)
109 ATTR_NONNULL(1, 3, 4);
110
118 char *table[],
119 const char *strings[],
120 uint strings_num) ATTR_NONNULL(2, 3);
121
122#define BLI_string_join_by_sep_char_with_tableN(sep, table, ...) \
123 BLI_string_join_array_by_sep_char_with_tableN( \
124 sep, table, ((const char *[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
125
137size_t BLI_string_flip_side_name(char *name_dst,
138 const char *name_src,
139 bool strip_number,
140 size_t name_dst_maxncpy) ATTR_NONNULL(1, 2);
141
154 void *arg,
155 const char *defname,
156 char delim,
157 char *name,
158 size_t name_maxncpy) ATTR_NONNULL(1, 3, 5);
159
168std::string BLI_uniquename_cb(blender::FunctionRef<bool(blender::StringRef)> unique_check,
169 char delim,
170 blender::StringRef name);
182void BLI_uniquename(const struct ListBase *list,
183 void *vlink,
184 const char *defname,
185 char delim,
186 int name_offset,
187 size_t name_maxncpy) ATTR_NONNULL(1, 3);
188
189/* Expand array functions. */
190
191size_t BLI_string_len_array(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT
192 ATTR_NONNULL();
193
194/* Intentionally no comma after `_BLI_STRING_ARGS_0` to allow it to be empty. */
195#define _BLI_STRING_ARGS_1 _BLI_STRING_ARGS_0 const char *a
196#define _BLI_STRING_ARGS_2 _BLI_STRING_ARGS_1, const char *b
197#define _BLI_STRING_ARGS_3 _BLI_STRING_ARGS_2, const char *c
198#define _BLI_STRING_ARGS_4 _BLI_STRING_ARGS_3, const char *d
199#define _BLI_STRING_ARGS_5 _BLI_STRING_ARGS_4, const char *e
200#define _BLI_STRING_ARGS_6 _BLI_STRING_ARGS_5, const char *f
201#define _BLI_STRING_ARGS_7 _BLI_STRING_ARGS_6, const char *g
202#define _BLI_STRING_ARGS_8 _BLI_STRING_ARGS_7, const char *h
203#define _BLI_STRING_ARGS_9 _BLI_STRING_ARGS_8, const char *i
204#define _BLI_STRING_ARGS_10 _BLI_STRING_ARGS_9, const char *j
205
206/* ------------------------------------------------------------------------- */
210#define _BLI_STRING_ARGS_0 char *__restrict dst, const size_t dst_len,
211
215size_t BLI_string_join_array(char *result,
216 size_t result_maxncpy,
217 const char *strings[],
218 uint strings_num) ATTR_NONNULL();
219
220#define BLI_string_join(...) VA_NARGS_CALL_OVERLOAD(_BLI_string_join_, __VA_ARGS__)
221
232
234{
235 const char *string_array[] = {a};
236 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
237}
239{
240 const char *string_array[] = {a, b};
241 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
242}
244{
245 const char *string_array[] = {a, b, c};
246 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
247}
249{
250 const char *string_array[] = {a, b, c, d};
251 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
252}
254{
255 const char *string_array[] = {a, b, c, d, e};
256 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
257}
259{
260 const char *string_array[] = {a, b, c, d, e, f};
261 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
262}
264{
265 const char *string_array[] = {a, b, c, d, e, f, g};
266 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
267}
269{
270 const char *string_array[] = {a, b, c, d, e, f, g, h};
271 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
272}
274{
275 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
276 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
277}
279{
280 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
281 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
282}
283
284#undef _BLI_STRING_ARGS_0
285
288/* ------------------------------------------------------------------------- */
295char *BLI_string_join_arrayN(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT
296 ATTR_NONNULL();
297
298#define BLI_string_joinN(...) VA_NARGS_CALL_OVERLOAD(_BLI_string_joinN_, __VA_ARGS__)
299
300#define _BLI_STRING_ARGS_0
301
312
314{
315 const char *string_array[] = {a};
316 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
317}
319{
320 const char *string_array[] = {a, b};
321 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
322}
324{
325 const char *string_array[] = {a, b, c};
326 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
327}
329{
330 const char *string_array[] = {a, b, c, d};
331 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
332}
334{
335 const char *string_array[] = {a, b, c, d, e};
336 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
337}
339{
340 const char *string_array[] = {a, b, c, d, e, f};
341 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
342}
344{
345 const char *string_array[] = {a, b, c, d, e, f, g};
346 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
347}
349{
350 const char *string_array[] = {a, b, c, d, e, f, g, h};
351 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
352}
354{
355 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
356 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
357}
359{
360 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
361 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
362}
363
364#undef _BLI_STRING_ARGS_0
365
368/* ------------------------------------------------------------------------- */
376size_t BLI_string_join_array_by_sep_char(char *result,
377 size_t result_maxncpy,
378 char sep,
379 const char *strings[],
380 uint strings_num) ATTR_NONNULL();
381
382#define BLI_string_join_by_sep_char(...) \
383 VA_NARGS_CALL_OVERLOAD(_BLI_string_join_by_sep_char_, __VA_ARGS__)
384
385#define _BLI_STRING_ARGS_0 char *__restrict dst, const size_t dst_len, const char sep,
386
397
399{
400 const char *string_array[] = {a};
402 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
403}
405{
406 const char *string_array[] = {a, b};
408 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
409}
411{
412 const char *string_array[] = {a, b, c};
414 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
415}
417{
418 const char *string_array[] = {a, b, c, d};
420 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
421}
423{
424 const char *string_array[] = {a, b, c, d, e};
426 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
427}
429{
430 const char *string_array[] = {a, b, c, d, e, f};
432 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
433}
435{
436 const char *string_array[] = {a, b, c, d, e, f, g};
438 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
439}
441{
442 const char *string_array[] = {a, b, c, d, e, f, g, h};
444 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
445}
447{
448 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
450 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
451}
453{
454 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
456 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
457}
458
459#undef _BLI_STRING_ARGS_0
460
463/* ------------------------------------------------------------------------- */
472 const char *strings[],
474
475#define BLI_string_join_by_sep_charN(...) \
476 VA_NARGS_CALL_OVERLOAD(_BLI_string_join_by_sep_charN_, __VA_ARGS__)
477
478#define _BLI_STRING_ARGS_0 const char sep,
479
490
492{
493 const char *string_array[] = {a};
494 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
495}
497{
498 const char *string_array[] = {a, b};
499 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
500}
502{
503 const char *string_array[] = {a, b, c};
504 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
505}
507{
508 const char *string_array[] = {a, b, c, d};
509 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
510}
512{
513 const char *string_array[] = {a, b, c, d, e};
514 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
515}
517{
518 const char *string_array[] = {a, b, c, d, e, f};
519 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
520}
522{
523 const char *string_array[] = {a, b, c, d, e, f, g};
524 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
525}
527{
528 const char *string_array[] = {a, b, c, d, e, f, g, h};
529 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
530}
532{
533 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
534 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
535}
537{
538 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
539 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
540}
541
544#undef _BLI_STRING_ARGS_0
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_NONNULL(...)
#define BLI_INLINE
BLI_INLINE char * _BLI_string_join_by_sep_charN_7(_BLI_STRING_ARGS_6) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_6(_BLI_STRING_ARGS_4) ATTR_NONNULL()
size_t BLI_string_flip_side_name(char *name_dst, const char *name_src, bool strip_number, size_t name_dst_maxncpy) ATTR_NONNULL(1
BLI_INLINE size_t _BLI_string_join_5(_BLI_STRING_ARGS_3) ATTR_NONNULL()
#define _BLI_STRING_ARGS_4
size_t BLI_string_join_array_by_sep_char(char *result, size_t result_maxncpy, char sep, const char *strings[], uint strings_num) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_9(_BLI_STRING_ARGS_7) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_join_by_sep_charN_2(_BLI_STRING_ARGS_1) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_3(_BLI_STRING_ARGS_3) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_7(_BLI_STRING_ARGS_4) ATTR_NONNULL()
void void char * BLI_string_join_array_by_sep_char_with_tableN(char sep, char *table[], const char *strings[], uint strings_num) ATTR_NONNULL(2
BLI_INLINE char * _BLI_string_joinN_10(_BLI_STRING_ARGS_10) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_join_by_sep_charN_11(_BLI_STRING_ARGS_10) ATTR_NONNULL()
#define _BLI_STRING_ARGS_10
BLI_INLINE size_t _BLI_string_join_12(_BLI_STRING_ARGS_10) ATTR_NONNULL()
size_t BLI_string_split_name_number(const char *name, char delim, char *r_name_left, int *r_number) ATTR_NONNULL(1
BLI_INLINE size_t _BLI_string_join_3(_BLI_STRING_ARGS_1) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_4(_BLI_STRING_ARGS_4) ATTR_NONNULL()
void void BLI_string_split_prefix(const char *string, size_t string_maxlen, char *r_pre, char *r_body) ATTR_NONNULL(1
BLI_INLINE size_t _BLI_string_join_by_sep_char_5(_BLI_STRING_ARGS_2) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_8(_BLI_STRING_ARGS_6) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_6(_BLI_STRING_ARGS_3) ATTR_NONNULL()
void BLI_string_split_suffix(const char *string, size_t string_maxlen, char *r_body, char *r_suf) ATTR_NONNULL(1
BLI_INLINE size_t _BLI_string_join_by_sep_char_9(_BLI_STRING_ARGS_6) ATTR_NONNULL()
size_t void BLI_uniquename_cb(UniquenameCheckCallback unique_check, void *arg, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(1
#define _BLI_STRING_ARGS_6
BLI_INLINE size_t _BLI_string_join_4(_BLI_STRING_ARGS_2) ATTR_NONNULL()
char * BLI_string_join_arrayN(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BLI_INLINE char * _BLI_string_join_by_sep_charN_3(_BLI_STRING_ARGS_2) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_4(_BLI_STRING_ARGS_1) ATTR_NONNULL()
char ATTR_MALLOC
BLI_INLINE char * _BLI_string_joinN_5(_BLI_STRING_ARGS_5) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_8(_BLI_STRING_ARGS_8) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_join_by_sep_charN_9(_BLI_STRING_ARGS_8) ATTR_NONNULL()
#define _BLI_STRING_ARGS_5
BLI_INLINE char * _BLI_string_joinN_6(_BLI_STRING_ARGS_6) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_10(_BLI_STRING_ARGS_7) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_11(_BLI_STRING_ARGS_8) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_8(_BLI_STRING_ARGS_5) ATTR_NONNULL()
void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1)
BLI_INLINE char * _BLI_string_join_by_sep_charN_4(_BLI_STRING_ARGS_3) ATTR_NONNULL()
char * BLI_string_join_array_by_sep_charN(char sep, const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
#define _BLI_STRING_ARGS_3
BLI_INLINE size_t _BLI_string_join_11(_BLI_STRING_ARGS_9) ATTR_NONNULL()
size_t BLI_string_replace_range(char *string, size_t string_maxncpy, int src_beg, int src_end, const char *dst)
BLI_INLINE size_t _BLI_string_join_by_sep_char_12(_BLI_STRING_ARGS_9) ATTR_NONNULL()
bool(*)(void *arg, const char *name) UniquenameCheckCallback
size_t BLI_string_join_array(char *result, size_t result_maxncpy, const char *strings[], uint strings_num) ATTR_NONNULL()
size_t bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(1)
BLI_INLINE size_t _BLI_string_join_10(_BLI_STRING_ARGS_8) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_join_by_sep_charN_6(_BLI_STRING_ARGS_5) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_9(_BLI_STRING_ARGS_9) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_1(_BLI_STRING_ARGS_1) ATTR_NONNULL()
void BLI_uniquename(const struct ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
BLI_INLINE char * _BLI_string_join_by_sep_charN_10(_BLI_STRING_ARGS_9) ATTR_NONNULL()
#define _BLI_STRING_ARGS_1
BLI_INLINE char * _BLI_string_joinN_2(_BLI_STRING_ARGS_2) ATTR_NONNULL()
void size_t BLI_string_len_array(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_7(_BLI_STRING_ARGS_7) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_7(_BLI_STRING_ARGS_5) ATTR_NONNULL()
#define _BLI_STRING_ARGS_7
#define _BLI_STRING_ARGS_8
#define _BLI_STRING_ARGS_9
BLI_INLINE char * _BLI_string_join_by_sep_charN_5(_BLI_STRING_ARGS_4) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_join_by_sep_charN_8(_BLI_STRING_ARGS_7) ATTR_NONNULL()
char * BLI_string_replaceN(const char *__restrict str, const char *__restrict substr_old, const char *__restrict substr_new) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
#define _BLI_STRING_ARGS_2
BLI_INLINE size_t _BLI_string_join_by_sep_char_13(_BLI_STRING_ARGS_10) ATTR_NONNULL()
bool BLI_string_replace_table_exact(char *string, size_t string_len, const char *replace_table[][2], int replace_table_len)
unsigned int uint
#define ARRAY_SIZE(arr)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
local_group_size(16, 16) .push_constant(Type b
#define str(s)