Blender V5.0
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
10
11#include <cstdarg>
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
21/* ------------------------------------------------------------------------- */
24
38char *BLI_string_replaceN(const char *__restrict str,
39 const char *__restrict substr_old,
40 const char *__restrict substr_new) ATTR_WARN_UNUSED_RESULT
42
46void BLI_string_replace(std::string &haystack,
47 blender::StringRef needle,
48 blender::StringRef other);
49
57void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1);
58
66bool BLI_string_replace_table_exact(char *string,
67 size_t string_maxncpy,
68 const char *replace_table[][2],
69 int replace_table_len);
70
78 char *string, size_t string_maxncpy, int src_beg, int src_end, const char *dst);
79
81
82/* ------------------------------------------------------------------------- */
85
100size_t BLI_string_split_name_number(const char *name, char delim, char *r_name_left, int *r_number)
101 ATTR_NONNULL(1, 3, 4);
103 char delim,
104 int &r_number);
105bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(1);
106
111void BLI_string_split_suffix(const char *string, size_t string_maxlen, char *r_body, char *r_suf)
112 ATTR_NONNULL(1, 3, 4);
116void BLI_string_split_prefix(const char *string, size_t string_maxlen, char *r_pre, char *r_body)
117 ATTR_NONNULL(1, 3, 4);
118
120
126 char *table[],
127 const char *strings[],
128 uint strings_num) ATTR_NONNULL(2, 3);
129
130#define BLI_string_join_by_sep_char_with_tableN(sep, table, ...) \
131 BLI_string_join_array_by_sep_char_with_tableN( \
132 sep, table, ((const char *[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
133
145size_t BLI_string_flip_side_name(char *name_dst,
146 const char *name_src,
147 bool strip_number,
148 size_t name_dst_maxncpy) ATTR_NONNULL(1, 2);
149
161 const char *defname,
162 char delim,
163 char *name,
164 size_t name_maxncpy) ATTR_NONNULL(2, 4);
165
179std::string BLI_uniquename_cb(blender::FunctionRef<bool(blender::StringRef)> unique_check,
180 char delim,
193void BLI_uniquename(const struct ListBase *list,
194 void *vlink,
195 const char *defname,
196 char delim,
197 int name_offset,
198 size_t name_maxncpy) ATTR_NONNULL(1, 3);
199
200/* Expand array functions. */
201
202size_t BLI_string_len_array(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT
203 ATTR_NONNULL();
204
205/* Intentionally no comma after `_BLI_STRING_ARGS_0` to allow it to be empty. */
206#define _BLI_STRING_ARGS_1 _BLI_STRING_ARGS_0 const char *a
207#define _BLI_STRING_ARGS_2 _BLI_STRING_ARGS_1, const char *b
208#define _BLI_STRING_ARGS_3 _BLI_STRING_ARGS_2, const char *c
209#define _BLI_STRING_ARGS_4 _BLI_STRING_ARGS_3, const char *d
210#define _BLI_STRING_ARGS_5 _BLI_STRING_ARGS_4, const char *e
211#define _BLI_STRING_ARGS_6 _BLI_STRING_ARGS_5, const char *f
212#define _BLI_STRING_ARGS_7 _BLI_STRING_ARGS_6, const char *g
213#define _BLI_STRING_ARGS_8 _BLI_STRING_ARGS_7, const char *h
214#define _BLI_STRING_ARGS_9 _BLI_STRING_ARGS_8, const char *i
215#define _BLI_STRING_ARGS_10 _BLI_STRING_ARGS_9, const char *j
216
217/* ------------------------------------------------------------------------- */
220
221#define _BLI_STRING_ARGS_0 char *__restrict dst, const size_t dst_len,
222
226size_t BLI_string_join_array(char *result,
227 size_t result_maxncpy,
228 const char *strings[],
229 uint strings_num) ATTR_NONNULL();
230
231#define BLI_string_join(...) VA_NARGS_CALL_OVERLOAD(_BLI_string_join_, __VA_ARGS__)
232
243
245{
246 const char *string_array[] = {a};
247 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
248}
250{
251 const char *string_array[] = {a, b};
252 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
253}
255{
256 const char *string_array[] = {a, b, c};
257 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
258}
260{
261 const char *string_array[] = {a, b, c, d};
262 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
263}
265{
266 const char *string_array[] = {a, b, c, d, e};
267 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
268}
270{
271 const char *string_array[] = {a, b, c, d, e, f};
272 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
273}
275{
276 const char *string_array[] = {a, b, c, d, e, f, g};
277 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
278}
280{
281 const char *string_array[] = {a, b, c, d, e, f, g, h};
282 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
283}
285{
286 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
287 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
288}
290{
291 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
292 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
293}
294
295#undef _BLI_STRING_ARGS_0
296
298
299/* ------------------------------------------------------------------------- */
302
306char *BLI_string_join_arrayN(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT
307 ATTR_NONNULL();
308
309#define BLI_string_joinN(...) VA_NARGS_CALL_OVERLOAD(_BLI_string_joinN_, __VA_ARGS__)
310
311#define _BLI_STRING_ARGS_0
312
323
325{
326 const char *string_array[] = {a};
327 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
328}
330{
331 const char *string_array[] = {a, b};
332 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
333}
335{
336 const char *string_array[] = {a, b, c};
337 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
338}
340{
341 const char *string_array[] = {a, b, c, d};
342 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
343}
345{
346 const char *string_array[] = {a, b, c, d, e};
347 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
348}
350{
351 const char *string_array[] = {a, b, c, d, e, f};
352 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
353}
355{
356 const char *string_array[] = {a, b, c, d, e, f, g};
357 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
358}
360{
361 const char *string_array[] = {a, b, c, d, e, f, g, h};
362 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
363}
365{
366 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
367 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
368}
370{
371 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
372 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
373}
374
375#undef _BLI_STRING_ARGS_0
376
378
379/* ------------------------------------------------------------------------- */
382
388 size_t result_maxncpy,
389 char sep,
390 const char *strings[],
391 uint strings_num) ATTR_NONNULL();
392
393#define BLI_string_join_by_sep_char(...) \
394 VA_NARGS_CALL_OVERLOAD(_BLI_string_join_by_sep_char_, __VA_ARGS__)
395
396#define _BLI_STRING_ARGS_0 char *__restrict dst, const size_t dst_len, const char sep,
397
408
410{
411 const char *string_array[] = {a};
413 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
414}
416{
417 const char *string_array[] = {a, b};
419 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
420}
422{
423 const char *string_array[] = {a, b, c};
425 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
426}
428{
429 const char *string_array[] = {a, b, c, d};
431 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
432}
434{
435 const char *string_array[] = {a, b, c, d, e};
437 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
438}
440{
441 const char *string_array[] = {a, b, c, d, e, f};
443 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
444}
446{
447 const char *string_array[] = {a, b, c, d, e, f, g};
449 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
450}
452{
453 const char *string_array[] = {a, b, c, d, e, f, g, h};
455 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
456}
458{
459 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
461 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
462}
464{
465 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
467 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
468}
469
470#undef _BLI_STRING_ARGS_0
471
473
474/* ------------------------------------------------------------------------- */
477
483 const char *strings[],
485
486#define BLI_string_join_by_sep_charN(...) \
487 VA_NARGS_CALL_OVERLOAD(_BLI_string_join_by_sep_charN_, __VA_ARGS__)
488
489#define _BLI_STRING_ARGS_0 const char sep,
490
501
503{
504 const char *string_array[] = {a};
505 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
506}
508{
509 const char *string_array[] = {a, b};
510 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
511}
513{
514 const char *string_array[] = {a, b, c};
515 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
516}
518{
519 const char *string_array[] = {a, b, c, d};
520 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
521}
523{
524 const char *string_array[] = {a, b, c, d, e};
525 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
526}
528{
529 const char *string_array[] = {a, b, c, d, e, f};
530 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
531}
533{
534 const char *string_array[] = {a, b, c, d, e, f, g};
535 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
536}
538{
539 const char *string_array[] = {a, b, c, d, e, f, g, h};
540 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
541}
543{
544 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
545 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
546}
548{
549 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
550 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
551}
552
554
555#undef _BLI_STRING_ARGS_0
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_MALLOC
#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()
bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(1)
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()
#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()
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()
size_t void BLI_uniquename_cb(blender::FunctionRef< bool(blender::StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
BLI_INLINE size_t _BLI_string_join_by_sep_char_10(_BLI_STRING_ARGS_7) ATTR_NONNULL()
void BLI_string_replace(std::string &haystack, blender::StringRef needle, blender::StringRef other)
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()
size_t BLI_string_join_array(char *result, size_t result_maxncpy, const char *strings[], uint strings_num) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_10(_BLI_STRING_ARGS_8) ATTR_NONNULL()
bool BLI_string_replace_table_exact(char *string, size_t string_maxncpy, const char *replace_table[][2], int replace_table_len)
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()
unsigned int uint
#define ARRAY_SIZE(arr)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
#define str(s)
const char * name
i
Definition text_draw.cc:230