Blender V5.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
10
11#include <cstdarg>
12#include <string>
13
14#include "BLI_compiler_attrs.hh"
15#include "BLI_function_ref.hh"
16#include "BLI_string_ref.hh"
17#include "BLI_utildefines.hh"
18
19namespace blender {
20
21struct ListBase;
22
23/* ------------------------------------------------------------------------- */
26
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
48void BLI_string_replace(std::string &haystack, StringRef needle, StringRef other);
49
59
67void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1);
68
76bool BLI_string_replace_table_exact(char *string,
77 size_t string_maxncpy,
78 const char *replace_table[][2],
79 int replace_table_len);
80
88 char *string, size_t string_maxncpy, int src_beg, int src_end, const char *dst);
89
91
92/* ------------------------------------------------------------------------- */
95
110size_t BLI_string_split_name_number(const char *name, char delim, char *r_name_left, int *r_number)
111 ATTR_NONNULL(1, 3, 4);
112StringRef BLI_string_split_name_number(const StringRef name_full, char delim, int &r_number);
113bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(1);
114
119void BLI_string_split_suffix(const char *string, size_t string_maxlen, char *r_body, char *r_suf)
120 ATTR_NONNULL(1, 3, 4);
124void BLI_string_split_prefix(const char *string, size_t string_maxlen, char *r_pre, char *r_body)
125 ATTR_NONNULL(1, 3, 4);
126
128
134 char *table[],
135 const char *strings[],
136 uint strings_num) ATTR_NONNULL(2, 3);
137
138#define BLI_string_join_by_sep_char_with_tableN(sep, table, ...) \
139 BLI_string_join_array_by_sep_char_with_tableN( \
140 sep, table, ((const char *[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
141
153size_t BLI_string_flip_side_name(char *name_dst,
154 const char *name_src,
155 bool strip_number,
156 size_t name_dst_maxncpy) ATTR_NONNULL(1, 2);
157
168void BLI_uniquename_cb(FunctionRef<bool(StringRefNull)> unique_check,
169 const char *defname,
170 char delim,
171 char *name,
172 size_t name_maxncpy) ATTR_NONNULL(2, 4);
173
187std::string BLI_uniquename_cb(FunctionRef<bool(StringRef)> unique_check,
188 char delim,
189 StringRef name);
201void BLI_uniquename(const ListBase *list,
202 void *vlink,
203 const char *defname,
204 char delim,
205 int name_offset,
206 size_t name_maxncpy) ATTR_NONNULL(1, 3);
207
208/* Expand array functions. */
209
210size_t BLI_string_len_array(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT
211 ATTR_NONNULL();
212
213/* Intentionally no comma after `_BLI_STRING_ARGS_0` to allow it to be empty. */
214#define _BLI_STRING_ARGS_1 _BLI_STRING_ARGS_0 const char *a
215#define _BLI_STRING_ARGS_2 _BLI_STRING_ARGS_1, const char *b
216#define _BLI_STRING_ARGS_3 _BLI_STRING_ARGS_2, const char *c
217#define _BLI_STRING_ARGS_4 _BLI_STRING_ARGS_3, const char *d
218#define _BLI_STRING_ARGS_5 _BLI_STRING_ARGS_4, const char *e
219#define _BLI_STRING_ARGS_6 _BLI_STRING_ARGS_5, const char *f
220#define _BLI_STRING_ARGS_7 _BLI_STRING_ARGS_6, const char *g
221#define _BLI_STRING_ARGS_8 _BLI_STRING_ARGS_7, const char *h
222#define _BLI_STRING_ARGS_9 _BLI_STRING_ARGS_8, const char *i
223#define _BLI_STRING_ARGS_10 _BLI_STRING_ARGS_9, const char *j
224
225/* ------------------------------------------------------------------------- */
228
229#define _BLI_STRING_ARGS_0 char *__restrict dst, const size_t dst_len,
230
234size_t BLI_string_join_array(char *result,
235 size_t result_maxncpy,
236 const char *strings[],
237 uint strings_num) ATTR_NONNULL();
238
239#define BLI_string_join(...) VA_NARGS_CALL_OVERLOAD(_BLI_string_join_, __VA_ARGS__)
240
251
253{
254 const char *string_array[] = {a};
255 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
256}
258{
259 const char *string_array[] = {a, b};
260 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
261}
263{
264 const char *string_array[] = {a, b, c};
265 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
266}
268{
269 const char *string_array[] = {a, b, c, d};
270 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
271}
273{
274 const char *string_array[] = {a, b, c, d, e};
275 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
276}
278{
279 const char *string_array[] = {a, b, c, d, e, f};
280 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
281}
283{
284 const char *string_array[] = {a, b, c, d, e, f, g};
285 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
286}
288{
289 const char *string_array[] = {a, b, c, d, e, f, g, h};
290 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
291}
293{
294 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
295 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
296}
298{
299 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
300 return BLI_string_join_array(dst, dst_len, string_array, ARRAY_SIZE(string_array));
301}
302
303#undef _BLI_STRING_ARGS_0
304
306
307/* ------------------------------------------------------------------------- */
310
314char *BLI_string_join_arrayN(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT
315 ATTR_NONNULL();
316
317#define BLI_string_joinN(...) VA_NARGS_CALL_OVERLOAD(_BLI_string_joinN_, __VA_ARGS__)
318
319#define _BLI_STRING_ARGS_0
320
331
333{
334 const char *string_array[] = {a};
335 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
336}
338{
339 const char *string_array[] = {a, b};
340 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
341}
343{
344 const char *string_array[] = {a, b, c};
345 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
346}
348{
349 const char *string_array[] = {a, b, c, d};
350 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
351}
353{
354 const char *string_array[] = {a, b, c, d, e};
355 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
356}
358{
359 const char *string_array[] = {a, b, c, d, e, f};
360 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
361}
363{
364 const char *string_array[] = {a, b, c, d, e, f, g};
365 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
366}
368{
369 const char *string_array[] = {a, b, c, d, e, f, g, h};
370 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
371}
373{
374 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
375 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
376}
378{
379 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
380 return BLI_string_join_arrayN(string_array, ARRAY_SIZE(string_array));
381}
382
383#undef _BLI_STRING_ARGS_0
384
386
387/* ------------------------------------------------------------------------- */
390
396 size_t result_maxncpy,
397 char sep,
398 const char *strings[],
399 uint strings_num) ATTR_NONNULL();
400
401#define BLI_string_join_by_sep_char(...) \
402 VA_NARGS_CALL_OVERLOAD(_BLI_string_join_by_sep_char_, __VA_ARGS__)
403
404#define _BLI_STRING_ARGS_0 char *__restrict dst, const size_t dst_len, const char sep,
405
416
418{
419 const char *string_array[] = {a};
421 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
422}
424{
425 const char *string_array[] = {a, b};
427 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
428}
430{
431 const char *string_array[] = {a, b, c};
433 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
434}
436{
437 const char *string_array[] = {a, b, c, d};
439 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
440}
442{
443 const char *string_array[] = {a, b, c, d, e};
445 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
446}
448{
449 const char *string_array[] = {a, b, c, d, e, f};
451 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
452}
454{
455 const char *string_array[] = {a, b, c, d, e, f, g};
457 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
458}
460{
461 const char *string_array[] = {a, b, c, d, e, f, g, h};
463 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
464}
466{
467 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
469 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
470}
472{
473 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
475 dst, dst_len, sep, string_array, ARRAY_SIZE(string_array));
476}
477
478#undef _BLI_STRING_ARGS_0
479
481
482/* ------------------------------------------------------------------------- */
485
491 const char *strings[],
493
494#define BLI_string_join_by_sep_charN(...) \
495 VA_NARGS_CALL_OVERLOAD(_BLI_string_join_by_sep_charN_, __VA_ARGS__)
496
497#define _BLI_STRING_ARGS_0 const char sep,
498
509
511{
512 const char *string_array[] = {a};
513 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
514}
516{
517 const char *string_array[] = {a, b};
518 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
519}
521{
522 const char *string_array[] = {a, b, c};
523 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
524}
526{
527 const char *string_array[] = {a, b, c, d};
528 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
529}
531{
532 const char *string_array[] = {a, b, c, d, e};
533 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
534}
536{
537 const char *string_array[] = {a, b, c, d, e, f};
538 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
539}
541{
542 const char *string_array[] = {a, b, c, d, e, f, g};
543 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
544}
546{
547 const char *string_array[] = {a, b, c, d, e, f, g, h};
548 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
549}
551{
552 const char *string_array[] = {a, b, c, d, e, f, g, h, i};
553 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
554}
556{
557 const char *string_array[] = {a, b, c, d, e, f, g, h, i, j};
558 return BLI_string_join_array_by_sep_charN(sep, string_array, ARRAY_SIZE(string_array));
559}
560
562
563#undef _BLI_STRING_ARGS_0
564
565} // namespace blender
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_NONNULL(...)
#define _BLI_STRING_ARGS_4
#define _BLI_STRING_ARGS_10
#define _BLI_STRING_ARGS_6
#define _BLI_STRING_ARGS_5
#define _BLI_STRING_ARGS_3
#define _BLI_STRING_ARGS_1
#define _BLI_STRING_ARGS_7
#define _BLI_STRING_ARGS_8
#define _BLI_STRING_ARGS_9
#define _BLI_STRING_ARGS_2
#define BLI_INLINE
#define str(s)
BMesh Iterators.
BLI_INLINE char * _BLI_string_joinN_4(_BLI_STRING_ARGS_4) ATTR_NONNULL()
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 size_t _BLI_string_join_6(_BLI_STRING_ARGS_4) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_join_by_sep_charN_4(_BLI_STRING_ARGS_3) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_7(_BLI_STRING_ARGS_4) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_1(_BLI_STRING_ARGS_1) ATTR_NONNULL()
unsigned int uint
Definition BKE_text.h:55
BLI_INLINE char * _BLI_string_join_by_sep_charN_11(_BLI_STRING_ARGS_10) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_join_by_sep_charN_9(_BLI_STRING_ARGS_8) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_join_by_sep_charN_10(_BLI_STRING_ARGS_9) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_3(_BLI_STRING_ARGS_1) 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_7(_BLI_STRING_ARGS_6) ATTR_NONNULL()
char * BLI_string_join_arrayN(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_11(_BLI_STRING_ARGS_8) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_10(_BLI_STRING_ARGS_10) 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()
std::string BLI_string_pad_number_sign(blender::StringRef str)
BLI_INLINE size_t _BLI_string_join_4(_BLI_STRING_ARGS_2) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_10(_BLI_STRING_ARGS_7) ATTR_NONNULL()
char * BLI_string_join_array_by_sep_charN(char sep, const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_5(_BLI_STRING_ARGS_3) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_7(_BLI_STRING_ARGS_7) 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_9(_BLI_STRING_ARGS_6) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_5(_BLI_STRING_ARGS_5) ATTR_NONNULL()
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
void BLI_uniquename(const 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_8(_BLI_STRING_ARGS_7) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_12(_BLI_STRING_ARGS_9) 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 size_t _BLI_string_join_9(_BLI_STRING_ARGS_7) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_6(_BLI_STRING_ARGS_3) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_8(_BLI_STRING_ARGS_6) ATTR_NONNULL()
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
BLI_INLINE char * _BLI_string_joinN_3(_BLI_STRING_ARGS_3) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_2(_BLI_STRING_ARGS_2) ATTR_NONNULL()
void void BLI_string_split_prefix(const char *string, size_t string_maxlen, char *r_pre, char *r_body) ATTR_NONNULL(1
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_12(_BLI_STRING_ARGS_10) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_13(_BLI_STRING_ARGS_10) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_11(_BLI_STRING_ARGS_9) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_8(_BLI_STRING_ARGS_8) ATTR_NONNULL()
void size_t BLI_string_len_array(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT 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
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_8(_BLI_STRING_ARGS_5) ATTR_NONNULL()
BLI_INLINE char * _BLI_string_joinN_6(_BLI_STRING_ARGS_6) ATTR_NONNULL()
BLI_INLINE size_t _BLI_string_join_by_sep_char_5(_BLI_STRING_ARGS_2) ATTR_NONNULL()
bool ATTR_WARN_UNUSED_RESULT
size_t BLI_string_split_name_number(const char *name, char delim, char *r_name_left, int *r_number) ATTR_NONNULL(1
void ATTR_NONNULL(1, 2)
size_t BLI_string_join_array(char *result, size_t result_maxncpy, const char *strings[], uint strings_num) ATTR_NONNULL()
void BLI_string_replace(std::string &haystack, StringRef needle, StringRef other)
char ATTR_MALLOC
Definition BLI_string.hh:79
BLI_INLINE size_t _BLI_string_join_7(_BLI_STRING_ARGS_5) ATTR_NONNULL()
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_6(_BLI_STRING_ARGS_5) ATTR_NONNULL()
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
BLI_INLINE char * _BLI_string_joinN_9(_BLI_STRING_ARGS_9) 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
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_2(_BLI_STRING_ARGS_1) ATTR_NONNULL()