Blender V5.3
blenlib/intern/string.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cctype>
11#include <cinttypes>
12#include <cmath>
13#include <cstdarg>
14#include <cstdio>
15#include <cstdlib>
16#include <cstring>
17
18#include "MEM_guardedalloc.h"
19
20#include "BLI_string.hh"
21
22#include "BLI_utildefines.hh"
23
24#include "BLI_strict_flags.hh" /* IWYU pragma: keep. Keep last. */
25
26namespace blender {
27
28/* -------------------------------------------------------------------- */
31
32char *BLI_strdupn(const char *str, const size_t len)
33{
34 BLI_assert_msg(BLI_strnlen(str, len) == len, "strlen(str) must be greater or equal to 'len'!");
35
36 char *n = MEM_new_array_uninitialized<char>(len + 1, "strdup");
37 memcpy(n, str, len);
38 n[len] = '\0';
39
40 return n;
41}
42
43char *BLI_strdup(const char *str)
44{
45 return BLI_strdupn(str, strlen(str));
46}
47
48char *BLI_strdup_null(const char *str)
49{
50 return (str != nullptr) ? BLI_strdupn(str, strlen(str)) : nullptr;
51}
52
53char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2)
54{
55 /* Include the null terminator of `str2` only. */
56 const size_t str1_len = strlen(str1);
57 const size_t str2_len = strlen(str2) + 1;
58 char *str, *s;
59
60 str = MEM_new_array_zeroed<char>(str1_len + str2_len, "strdupcat");
61 s = str;
62
63 memcpy(s, str1, str1_len); /* NOLINT: bugprone-not-null-terminated-result */
64 s += str1_len;
65 memcpy(s, str2, str2_len);
66
67 return str;
68}
69
70char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy)
71{
72 BLI_string_debug_size(dst, dst_maxncpy);
73
74 BLI_assert(dst_maxncpy != 0);
75 size_t srclen = BLI_strnlen(src, dst_maxncpy - 1);
76
77 memcpy(dst, src, srclen);
78 dst[srclen] = '\0';
79 return dst;
80}
81
82char *BLI_strncpy_ensure_pad(char *__restrict dst,
83 const char *__restrict src,
84 const char pad,
85 size_t dst_maxncpy)
86{
87 BLI_string_debug_size(dst, dst_maxncpy);
88 BLI_assert(dst_maxncpy != 0);
89
90 if (src[0] == '\0') {
91 dst[0] = '\0';
92 }
93 else {
94 /* Add heading/trailing wildcards if needed. */
95 size_t idx = 0;
96 size_t srclen;
97
98 dst_maxncpy--; /* trailing '\0' */
99 if ((dst_maxncpy != 0) && (src[idx] != pad)) {
100 dst[idx++] = pad;
101 dst_maxncpy--;
102 }
103
104 srclen = BLI_strnlen(src, dst_maxncpy);
105 if ((srclen != 0) && (srclen == dst_maxncpy) && (src[srclen - 1] != pad)) {
106 srclen--;
107 }
108
109 memcpy(&dst[idx], src, srclen);
110 idx += srclen;
111
112 if ((idx != 0) && (dst[idx - 1] != pad)) {
113 dst[idx++] = pad;
114 }
115 dst[idx] = '\0';
116 }
117
118 return dst;
119}
120
121size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy)
122{
123 BLI_string_debug_size(dst, dst_maxncpy);
124
125 size_t srclen = BLI_strnlen(src, dst_maxncpy - 1);
126 BLI_assert(dst_maxncpy != 0);
127
128 memcpy(dst, src, srclen);
129 dst[srclen] = '\0';
130 return srclen;
131}
132
134
135/* -------------------------------------------------------------------- */
138
139char *BLI_strncat(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy)
140{
141 BLI_string_debug_size_after_nil(dst, dst_maxncpy);
142
143 size_t len = BLI_strnlen(dst, dst_maxncpy);
144 if (len < dst_maxncpy) {
145 BLI_strncpy(dst + len, src, dst_maxncpy - len);
146 }
147 return dst;
148}
149
151
152/* -------------------------------------------------------------------- */
155
156size_t BLI_vsnprintf(char *__restrict dst,
157 size_t dst_maxncpy,
158 const char *__restrict format,
159 va_list arg)
160{
161 BLI_string_debug_size(dst, dst_maxncpy);
162
163 BLI_assert(dst != nullptr);
164 BLI_assert(dst_maxncpy > 0);
165 BLI_assert(format != nullptr);
166
167 const size_t n = size_t(vsnprintf(dst, dst_maxncpy, format, arg));
168 if (n < dst_maxncpy) {
169 dst[n] = '\0';
170 }
171 else {
172 dst[dst_maxncpy - 1] = '\0';
173 }
174
175 return n;
176}
177
178size_t BLI_vsnprintf_rlen(char *__restrict dst,
179 size_t dst_maxncpy,
180 const char *__restrict format,
181 va_list arg)
182{
183 BLI_string_debug_size(dst, dst_maxncpy);
184
185 BLI_assert(dst != nullptr);
186 BLI_assert(dst_maxncpy > 0);
187 BLI_assert(format != nullptr);
188
189 size_t n = size_t(vsnprintf(dst, dst_maxncpy, format, arg));
190 if (n < dst_maxncpy) {
191 /* pass */
192 }
193 else {
194 n = dst_maxncpy - 1;
195 }
196 dst[n] = '\0';
197
198 return n;
199}
200
201size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format, ...)
202{
203 BLI_string_debug_size(dst, dst_maxncpy);
204
205 va_list arg;
206 va_start(arg, format);
207 const size_t n = BLI_vsnprintf(dst, dst_maxncpy, format, arg);
208 va_end(arg);
209
210 return n;
211}
212
213size_t BLI_snprintf_rlen(char *__restrict dst,
214 size_t dst_maxncpy,
215 const char *__restrict format,
216 ...)
217{
218 BLI_string_debug_size(dst, dst_maxncpy);
219
220 va_list arg;
221 va_start(arg, format);
222 const size_t n = BLI_vsnprintf_rlen(dst, dst_maxncpy, format, arg);
223 va_end(arg);
224
225 return n;
226}
227
228char *BLI_sprintfN_with_buffer(char *fixed_buf,
229 size_t fixed_buf_maxncpy,
230 size_t *result_len,
231 const char *__restrict format,
232 ...)
233{
234 va_list args;
235 va_start(args, format);
236 int retval = vsnprintf(fixed_buf, fixed_buf_maxncpy, format, args);
237 va_end(args);
238 if (retval < 0) [[unlikely]] {
239 /* Return an empty string as there was an error there is no valid output. */
240 *result_len = 0;
241 if (fixed_buf_maxncpy == 0) [[unlikely]] {
242 return MEM_new_array_zeroed<char>(1, __func__);
243 }
244 *fixed_buf = '\0';
245 return fixed_buf;
246 }
247 *result_len = size_t(retval);
248 if (size_t(retval) < fixed_buf_maxncpy) {
249 return fixed_buf;
250 }
251
252 /* `retval` doesn't include null terminator. */
253 const size_t size = size_t(retval) + 1;
254 char *result = MEM_new_array_uninitialized<char>(size, __func__);
255 va_start(args, format);
256 retval = vsnprintf(result, size, format, args);
257 va_end(args);
258 BLI_assert(size_t(retval + 1) == size);
259 UNUSED_VARS_NDEBUG(retval);
260 return result;
261}
262
263char *BLI_vsprintfN_with_buffer(char *fixed_buf,
264 size_t fixed_buf_maxncpy,
265 size_t *result_len,
266 const char *__restrict format,
267 va_list args)
268{
269 va_list args_copy;
270 va_copy(args_copy, args);
271 int retval = vsnprintf(fixed_buf, fixed_buf_maxncpy, format, args_copy);
272 va_end(args_copy);
273 if (retval < 0) [[unlikely]] {
274 /* Return an empty string as there was an error there is no valid output. */
275 *result_len = 0;
276 if (fixed_buf_maxncpy == 0) [[unlikely]] {
277 return MEM_new_array_zeroed<char>(1, __func__);
278 }
279 *fixed_buf = '\0';
280 return fixed_buf;
281 }
282 *result_len = size_t(retval);
283 if (size_t(retval) < fixed_buf_maxncpy) {
284 return fixed_buf;
285 }
286
287 /* `retval` doesn't include null terminator. */
288 const size_t size = size_t(retval) + 1;
289 char *result = MEM_new_array_uninitialized<char>(size, __func__);
290 retval = vsnprintf(result, size, format, args);
291 BLI_assert(size_t(retval + 1) == size);
292 UNUSED_VARS_NDEBUG(retval);
293 return result;
294}
295
296char *BLI_sprintfN(const char *__restrict format, ...)
297{
298 char fixed_buf[256];
299 size_t result_len;
300 va_list args;
301 va_start(args, format);
303 fixed_buf, sizeof(fixed_buf), &result_len, format, args);
304 va_end(args);
305 if (result != fixed_buf) {
306 return result;
307 }
308 size_t size = result_len + 1;
310 memcpy(result, fixed_buf, size);
311 return result;
312}
313
314char *BLI_vsprintfN(const char *__restrict format, va_list args)
315{
316 char fixed_buf[256];
317 size_t result_len;
319 fixed_buf, sizeof(fixed_buf), &result_len, format, args);
320 if (result != fixed_buf) {
321 return result;
322 }
323 size_t size = result_len + 1;
324 result = MEM_new_array_zeroed<char>(size, __func__);
325 memcpy(result, fixed_buf, size);
326 return result;
327}
328
330
331/* -------------------------------------------------------------------- */
334
335size_t BLI_str_escape(char *__restrict dst, StringRef src, const size_t dst_maxncpy)
336{
337 BLI_assert(dst_maxncpy != 0);
338 BLI_string_debug_size(dst, dst_maxncpy);
339
340 const size_t dst_len_max = dst_maxncpy - 1;
341 size_t dst_len = 0;
342 int64_t src_idx = 0;
343 for (; (dst_len < dst_len_max) && (src_idx < src.size()); src_idx++, dst++, dst_len++) {
344 char c = src[src_idx];
345 if (ELEM(c, '\\', '"') || /* Use as-is. */
346 ((c == '\t') && ((void)(c = 't'), true)) || /* Tab. */
347 ((c == '\n') && ((void)(c = 'n'), true)) || /* Newline. */
348 ((c == '\r') && ((void)(c = 'r'), true)) || /* Carriage return. */
349 ((c == '\a') && ((void)(c = 'a'), true)) || /* Bell. */
350 ((c == '\b') && ((void)(c = 'b'), true)) || /* Backspace. */
351 ((c == '\f') && ((void)(c = 'f'), true))) /* Form-feed. */
352 {
353 if (dst_len + 1 >= dst_len_max) [[unlikely]] {
354 /* Not enough space to escape. */
355 break;
356 }
357 *dst++ = '\\';
358 dst_len++;
359 }
360 *dst = c;
361 }
362 *dst = '\0';
363
364 return dst_len;
365}
366
368{
369 if (str.is_empty()) {
370 return {};
371 }
372 const size_t max_result_size = size_t(str.size()) * 2 + 1;
373 std::string result;
374 result.resize(max_result_size);
375 const size_t result_size = BLI_str_escape(result.data(), str, max_result_size);
376 result.resize(result_size);
377 return result;
378}
379
380BLI_INLINE bool str_unescape_pair(char c_next, char *r_out)
381{
382#define CASE_PAIR(value_src, value_dst) \
383 case value_src: { \
384 *r_out = value_dst; \
385 return true; \
386 }
387 switch (c_next) {
388 CASE_PAIR('"', '"'); /* Quote. */
389 CASE_PAIR('\\', '\\'); /* Backslash. */
390 CASE_PAIR('t', '\t'); /* Tab. */
391 CASE_PAIR('n', '\n'); /* Newline. */
392 CASE_PAIR('r', '\r'); /* Carriage return. */
393 CASE_PAIR('a', '\a'); /* Bell. */
394 CASE_PAIR('b', '\b'); /* Backspace. */
395 CASE_PAIR('f', '\f'); /* Form-feed. */
396 }
397#undef CASE_PAIR
398 return false;
399}
400
401size_t BLI_str_unescape_ex(char *__restrict dst,
402 const char *__restrict src,
403 const size_t src_len,
404 /* Additional arguments to #BLI_str_unescape */
405 const size_t dst_maxncpy,
406 bool *r_is_complete)
407{
408 BLI_string_debug_size(dst, dst_maxncpy);
409 BLI_assert(dst_maxncpy != 0);
410
411 size_t len = 0;
412 bool is_complete = true;
413 const size_t max_strlen = dst_maxncpy - 1; /* Account for trailing zero byte. */
414 for (const char *src_end = src + src_len; (src < src_end) && *src; src++) {
415 if (len == max_strlen) [[unlikely]] {
416 is_complete = false;
417 break;
418 }
419 char c = *src;
420 if (UNLIKELY(c == '\\') && (src + 1 < src_end) && str_unescape_pair(*(src + 1), &c)) {
421 src++;
422 }
423 dst[len++] = c;
424 }
425 dst[len] = 0;
426 *r_is_complete = is_complete;
427 return len;
428}
429
430size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const size_t src_len)
431{
432 BLI_string_debug_size(dst, src_len + 1); /* `dst` must be at least as big as `src`. */
433
434 size_t len = 0;
435 for (const char *src_end = src + src_len; (src < src_end) && *src; src++) {
436 char c = *src;
437 if (UNLIKELY(c == '\\') && (src + 1 < src_end) && str_unescape_pair(*(src + 1), &c)) {
438 src++;
439 }
440 dst[len++] = c;
441 }
442 dst[len] = 0;
443 return len;
444}
445
446const char *BLI_str_escape_find_quote(const char *str)
447{
448 bool escape = false;
449 while (*str && (*str != '"' || escape)) {
450 /* A pair of back-slashes represents a single back-slash,
451 * only use a single back-slash for escaping. */
452 escape = (escape == false) && (*str == '\\');
453 str++;
454 }
455 return (*str == '"') ? str : nullptr;
456}
457
459
460/* -------------------------------------------------------------------- */
463
464bool BLI_str_quoted_substr_range(const char *__restrict str,
465 const char *__restrict prefix,
466 int *__restrict r_start,
467 int *__restrict r_end)
468{
469 const char *str_start = strstr(str, prefix);
470 if (str_start == nullptr) {
471 return false;
472 }
473 const size_t prefix_len = strlen(prefix);
474 if (prefix_len == 0) [[unlikely]] {
476 "Zero length prefix passed in, "
477 "caller must prevent this from happening!");
478 return false;
479 }
480 BLI_assert_msg(prefix[prefix_len - 1] != '"',
481 "Prefix includes trailing quote, "
482 "caller must prevent this from happening!");
483
484 str_start += prefix_len;
485 if (*str_start != '\"') [[unlikely]] {
486 return false;
487 }
488 str_start += 1;
489 const char *str_end = BLI_str_escape_find_quote(str_start);
490 if (str_end == nullptr) [[unlikely]] {
491 return false;
492 }
493
494 *r_start = int(str_start - str);
495 *r_end = int(str_end - str);
496 return true;
497}
498
499/* NOTE(@ideasman42): in principal it should be possible to access a quoted string
500 * with an arbitrary size, currently all callers for this functionality
501 * happened to use a fixed size buffer, so only #BLI_str_quoted_substr is needed. */
502#if 0
513char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix)
514{
515 int start_match_ofs, end_match_ofs;
516 if (!BLI_str_quoted_substr_range(str, prefix, &start_match_ofs, &end_match_ofs)) {
517 return nullptr;
518 }
519 const size_t escaped_len = size_t(end_match_ofs - start_match_ofs);
520 char *result = MEM_new_array_uninitialized<char>(escaped_len + 1, __func__);
521 const size_t unescaped_len = BLI_str_unescape(result, str + start_match_ofs, escaped_len);
522 if (unescaped_len != escaped_len) {
523 result = MEM_realloc_uninitialized(result, sizeof(char) * (unescaped_len + 1));
524 }
525 return result;
526}
527#endif
528
529bool BLI_str_quoted_substr(const char *__restrict str,
530 const char *__restrict prefix,
531 char *result,
532 size_t result_maxncpy)
533{
534 BLI_string_debug_size(result, result_maxncpy);
535
536 int start_match_ofs, end_match_ofs;
537 if (!BLI_str_quoted_substr_range(str, prefix, &start_match_ofs, &end_match_ofs)) {
538 return false;
539 }
540 const size_t escaped_len = size_t(end_match_ofs - start_match_ofs);
541 bool is_complete;
542 BLI_str_unescape_ex(result, str + start_match_ofs, escaped_len, result_maxncpy, &is_complete);
543 if (is_complete == false) {
544 *result = '\0';
545 }
546 return is_complete;
547}
548
550
551/* -------------------------------------------------------------------- */
554
555int BLI_strcaseeq(const char *a, const char *b)
556{
557 return (BLI_strcasecmp(a, b) == 0);
558}
559
560char *BLI_strcasestr(const char *s, const char *find)
561{
562 char c, sc;
563 size_t len;
564
565 if ((c = *find++) != 0) {
566 c = char(tolower(c));
567 len = strlen(find);
568 do {
569 do {
570 if ((sc = *s++) == 0) {
571 return nullptr;
572 }
573 sc = char(tolower(sc));
574 } while (sc != c);
575 } while (BLI_strncasecmp(s, find, len) != 0);
576 s--;
577 }
578 return (const_cast<char *>(s));
579}
580
582{
583 return (str_len / 2) + 1;
584}
585
586bool BLI_string_has_word_prefix(const char *haystack, const char *needle, size_t needle_len)
587{
588 const char *match = BLI_strncasestr(haystack, needle, needle_len);
589 if (match) {
590 if ((match == haystack) || (*(match - 1) == ' ') || ispunct(*(match - 1))) {
591 return true;
592 }
593 return BLI_string_has_word_prefix(match + 1, needle, needle_len);
594 }
595 return false;
596}
597
598bool BLI_string_all_words_matched(const char *name,
599 const char *str,
600 int (*words)[2],
601 const int words_len)
602{
603 int index;
604 for (index = 0; index < words_len; index++) {
605 if (!BLI_string_has_word_prefix(name, str + words[index][0], size_t(words[index][1]))) {
606 break;
607 }
608 }
609 const bool all_words_matched = (index == words_len);
610
611 return all_words_matched;
612}
613
614char *BLI_strncasestr(const char *s, const char *find, size_t len)
615{
616 char c, sc;
617
618 if ((c = *find++) != 0) {
619 c = char(tolower(c));
620 if (len > 1) {
621 do {
622 do {
623 if ((sc = *s++) == 0) {
624 return nullptr;
625 }
626 sc = char(tolower(sc));
627 } while (sc != c);
628 } while (BLI_strncasecmp(s, find, len - 1) != 0);
629 }
630 else {
631 {
632 do {
633 if ((sc = *s++) == 0) {
634 return nullptr;
635 }
636 sc = char(tolower(sc));
637 } while (sc != c);
638 }
639 }
640 s--;
641 }
642 return (const_cast<char *>(s));
643}
644
645int BLI_strcasecmp(const char *s1, const char *s2)
646{
647 int i;
648 char c1, c2;
649
650 for (i = 0;; i++) {
651 c1 = char(tolower(s1[i]));
652 c2 = char(tolower(s2[i]));
653
654 if (c1 < c2) {
655 return -1;
656 }
657 if (c1 > c2) {
658 return 1;
659 }
660 if (c1 == 0) {
661 break;
662 }
663 }
664
665 return 0;
666}
667
668int BLI_strncasecmp(const char *s1, const char *s2, size_t len)
669{
670 size_t i;
671 char c1, c2;
672
673 for (i = 0; i < len; i++) {
674 c1 = char(tolower(s1[i]));
675 c2 = char(tolower(s2[i]));
676
677 if (c1 < c2) {
678 return -1;
679 }
680 if (c1 > c2) {
681 return 1;
682 }
683 if (c1 == 0) {
684 break;
685 }
686 }
687
688 return 0;
689}
690
691/* compare number on the left size of the string */
692static int left_number_strcmp(const char *s1, const char *s2, int *tiebreaker)
693{
694 const char *p1 = s1, *p2 = s2;
695 int numdigit, numzero1, numzero2;
696
697 /* count and skip leading zeros */
698 for (numzero1 = 0; *p1 == '0'; numzero1++) {
699 p1++;
700 }
701 for (numzero2 = 0; *p2 == '0'; numzero2++) {
702 p2++;
703 }
704
705 /* find number of consecutive digits */
706 for (numdigit = 0;; numdigit++) {
707 if (isdigit(*(p1 + numdigit)) && isdigit(*(p2 + numdigit))) {
708 continue;
709 }
710 if (isdigit(*(p1 + numdigit))) {
711 return 1; /* s2 is bigger */
712 }
713 if (isdigit(*(p2 + numdigit))) {
714 return -1; /* s1 is bigger */
715 }
716 break;
717 }
718
719 /* same number of digits, compare size of number */
720 if (numdigit > 0) {
721 int compare = strncmp(p1, p2, size_t(numdigit));
722
723 if (compare != 0) {
724 return compare;
725 }
726 }
727
728 /* use number of leading zeros as tie breaker if still equal */
729 if (*tiebreaker == 0) {
730 if (numzero1 > numzero2) {
731 *tiebreaker = 1;
732 }
733 else if (numzero1 < numzero2) {
734 *tiebreaker = -1;
735 }
736 }
737
738 return 0;
739}
740
741int BLI_strcasecmp_natural(const char *s1, const char *s2)
742{
743 int d1 = 0, d2 = 0;
744 char c1, c2;
745 int tiebreaker = 0;
746
747 /* if both chars are numeric, to a left_number_strcmp().
748 * then increase string deltas as long they are
749 * numeric, else do a tolower and char compare */
750
751 while (true) {
752 if (isdigit(s1[d1]) && isdigit(s2[d2])) {
753 int numcompare = left_number_strcmp(s1 + d1, s2 + d2, &tiebreaker);
754
755 if (numcompare != 0) {
756 return numcompare;
757 }
758
759 /* Some wasted work here, left_number_strcmp already consumes at least some digits. */
760 d1++;
761 while (isdigit(s1[d1])) {
762 d1++;
763 }
764 d2++;
765 while (isdigit(s2[d2])) {
766 d2++;
767 }
768 }
769
770 /* Test for end of strings first so that shorter strings are ordered in front. */
771 if (ELEM(0, s1[d1], s2[d2])) {
772 break;
773 }
774
775 c1 = char(tolower(s1[d1]));
776 c2 = char(tolower(s2[d2]));
777
778 if (c1 == c2) {
779 /* Continue iteration */
780 }
781 /* Check for '.' so "foo.bar" comes before "foo 1.bar". */
782 else if (c1 == '.') {
783 return -1;
784 }
785 else if (c2 == '.') {
786 return 1;
787 }
788 else if (c1 < c2) {
789 return -1;
790 }
791 else if (c1 > c2) {
792 return 1;
793 }
794
795 d1++;
796 d2++;
797 }
798
799 if (tiebreaker) {
800 return tiebreaker;
801 }
802
803 /* we might still have a different string because of lower/upper case, in
804 * that case fall back to regular string comparison */
805 return strcmp(s1, s2);
806}
807
808int BLI_strcmp_ignore_pad(const char *str1, const char *str2, const char pad)
809{
810 size_t str1_len, str2_len;
811
812 while (*str1 == pad) {
813 str1++;
814 }
815 while (*str2 == pad) {
816 str2++;
817 }
818
819 str1_len = strlen(str1);
820 str2_len = strlen(str2);
821
822 while (str1_len && (str1[str1_len - 1] == pad)) {
823 str1_len--;
824 }
825 while (str2_len && (str2[str2_len - 1] == pad)) {
826 str2_len--;
827 }
828
829 if (str1_len == str2_len) {
830 return strncmp(str1, str2, str2_len);
831 }
832 if (str1_len > str2_len) {
833 int ret = strncmp(str1, str2, str2_len);
834 if (ret == 0) {
835 ret = 1;
836 }
837 return ret;
838 }
839 {
840 int ret = strncmp(str1, str2, str1_len);
841 if (ret == 0) {
842 ret = -1;
843 }
844 return ret;
845 }
846}
847
849
850/* -------------------------------------------------------------------- */
853
854int BLI_str_index_in_array_n(const char *__restrict str,
855 const char **__restrict str_array,
856 const int str_array_len)
857{
858 int index;
859 const char **str_iter = str_array;
860
861 for (index = 0; index < str_array_len; str_iter++, index++) {
862 if (STREQ(str, *str_iter)) {
863 return index;
864 }
865 }
866 return -1;
867}
868
869int BLI_str_index_in_array(const char *__restrict str, const char **__restrict str_array)
870{
871 int index;
872 const char **str_iter = str_array;
873
874 for (index = 0; *str_iter; str_iter++, index++) {
875 if (STREQ(str, *str_iter)) {
876 return index;
877 }
878 }
879 return -1;
880}
881
882bool BLI_str_startswith(const char *__restrict str, const char *__restrict start)
883{
884 for (; *str && *start; str++, start++) {
885 if (*str != *start) {
886 return false;
887 }
888 }
889
890 return (*start == '\0');
891}
892
893bool BLI_strn_endswith(const char *__restrict str, const char *__restrict end, size_t str_len)
894{
895 size_t end_len = strlen(end);
896
897 if (end_len <= str_len) {
898 const char *iter = &str[str_len - end_len];
899 while (*iter) {
900 if (*iter++ != *end++) {
901 return false;
902 }
903 }
904 return true;
905 }
906 return false;
907}
908
909bool BLI_str_endswith(const char *__restrict str, const char *__restrict end)
910{
911 const size_t str_len = strlen(str);
912 return BLI_strn_endswith(str, end, str_len);
913}
914
916
917/* -------------------------------------------------------------------- */
920
921size_t BLI_strnlen(const char *str, const size_t maxlen)
922{
923 size_t len;
924
925 for (len = 0; len < maxlen; len++, str++) {
926 if (!*str) {
927 break;
928 }
929 }
930 return len;
931}
932
934
935/* -------------------------------------------------------------------- */
938
939const char *BLI_strchr_or_end(const char *str, const char ch)
940{
941 const char *p = str;
942 while (!ELEM(*p, ch, '\0')) {
943 p++;
944 }
945 return p;
946}
947
949
950/* -------------------------------------------------------------------- */
953
954char BLI_tolower_ascii(const char c)
955{
956 return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c;
957}
958
959char BLI_toupper_ascii(const char c)
960{
961 return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c;
962}
963
964void BLI_str_tolower_ascii(char *str, const size_t len)
965{
966 size_t i;
967
968 for (i = 0; (i < len) && str[i]; i++) {
969 str[i] = BLI_tolower_ascii(str[i]);
970 }
971}
972
973void BLI_str_toupper_ascii(char *str, const size_t len)
974{
975 size_t i;
976
977 for (i = 0; (i < len) && str[i]; i++) {
978 str[i] = BLI_toupper_ascii(str[i]);
979 }
980}
981
983
984/* -------------------------------------------------------------------- */
987
989{
990 for (int i = int(strlen(str)) - 1; i >= 0; i--) {
991 if (isspace(str[i])) {
992 str[i] = '\0';
993 }
994 else {
995 break;
996 }
997 }
998}
999
1000int BLI_str_rstrip_float_zero(char *str, const char pad)
1001{
1002 char *p = strchr(str, '.');
1003 int totstrip = 0;
1004 if (p) {
1005 char *end_p;
1006 p++; /* position at first decimal place */
1007 end_p = p + (strlen(p) - 1); /* position at last character */
1008 if (end_p > p) {
1009 while (end_p != p && *end_p == '0') {
1010 *end_p = pad;
1011 end_p--;
1012 totstrip++;
1013 }
1014 }
1015 }
1016
1017 return totstrip;
1018}
1019
1021{
1022 int totstrip = 0;
1023 int str_len = int(strlen(str));
1024 while (str_len > 0 && isdigit(str[str_len - 1])) {
1025 --str_len;
1026 str[str_len] = '\0';
1027 totstrip++;
1028 }
1029 return totstrip;
1030}
1031
1033
1034/* -------------------------------------------------------------------- */
1037
1038size_t BLI_str_partition(const char *str, const char delim[], const char **sep, const char **suf)
1039{
1040 return BLI_str_partition_ex(str, nullptr, delim, sep, suf, false);
1041}
1042
1043size_t BLI_str_rpartition(const char *str, const char delim[], const char **sep, const char **suf)
1044{
1045 return BLI_str_partition_ex(str, nullptr, delim, sep, suf, true);
1046}
1047
1048size_t BLI_str_partition_ex(const char *str,
1049 const char *end,
1050 const char delim[],
1051 const char **sep,
1052 const char **suf,
1053 const bool from_right)
1054{
1055 const char *d;
1056
1057 BLI_assert(end == nullptr || end > str);
1058
1059 *sep = *suf = nullptr;
1060
1061 for (d = delim; *d != '\0'; d++) {
1062 const char *tmp;
1063
1064 if (end) {
1065 if (from_right) {
1066 for (tmp = end - 1; (tmp >= str) && (*tmp != *d); tmp--) {
1067 /* pass */
1068 }
1069 if (tmp < str) {
1070 tmp = nullptr;
1071 }
1072 }
1073 else {
1074 tmp = strchr(str, *d);
1075 if (tmp >= end) {
1076 tmp = nullptr;
1077 }
1078 }
1079 }
1080 else {
1081 tmp = (from_right) ? strrchr(str, *d) : strchr(str, *d);
1082 }
1083
1084 if (tmp && (from_right ? (*sep < tmp) : (!*sep || *sep > tmp))) {
1085 *sep = tmp;
1086 }
1087 }
1088
1089 if (*sep) {
1090 *suf = *sep + 1;
1091 return size_t(*sep - str);
1092 }
1093
1094 return end ? size_t(end - str) : strlen(str);
1095}
1096
1098 const char *str, const size_t str_maxlen, const char delim, int r_words[][2], int words_max)
1099{
1100 int n = 0, i;
1101 bool charsearch = true;
1102
1103 /* Skip leading spaces */
1104 for (i = 0; (i < int(str_maxlen)) && (str[i] != '\0'); i++) {
1105 if (str[i] != delim) {
1106 break;
1107 }
1108 }
1109
1110 for (; (i < int(str_maxlen)) && (str[i] != '\0') && (n < words_max); i++) {
1111 if ((str[i] != delim) && (charsearch == true)) {
1112 r_words[n][0] = i;
1113 charsearch = false;
1114 }
1115 else {
1116 if ((str[i] == delim) && (charsearch == false)) {
1117 r_words[n][1] = i - r_words[n][0];
1118 n++;
1119 charsearch = true;
1120 }
1121 }
1122 }
1123
1124 if (charsearch == false) {
1125 r_words[n][1] = i - r_words[n][0];
1126 n++;
1127 }
1128
1129 return n;
1130}
1131
1132bool BLI_string_elem_split_by_delim(const char *haystack, const char delim, const char *needle)
1133{
1134 /* May be zero, returns true when an empty span exists. */
1135 const size_t needle_len = strlen(needle);
1136 const char *p = haystack;
1137 while (true) {
1138 const char *p_next = BLI_strchr_or_end(p, delim);
1139 if ((size_t(p_next - p) == needle_len) && (memcmp(p, needle, needle_len) == 0)) {
1140 return true;
1141 }
1142 if (*p_next == '\0') {
1143 break;
1144 }
1145 p = p_next + 1;
1146 }
1147 return false;
1148}
1149
1151
1152/* -------------------------------------------------------------------- */
1155
1156static size_t BLI_str_format_int_grouped_ex(char *src, char *dst, int num_len)
1157{
1158 char *p_src = src;
1159 char *p_dst = dst;
1160
1161 const char separator = ',';
1162 int commas;
1163
1164 if (*p_src == '-') {
1165 *p_dst++ = *p_src++;
1166 num_len--;
1167 }
1168
1169 for (commas = 2 - num_len % 3; *p_src; commas = (commas + 1) % 3) {
1170 *p_dst++ = *p_src++;
1171 if (commas == 1) {
1172 *p_dst++ = separator;
1173 }
1174 }
1175 *--p_dst = '\0';
1176
1177 return size_t(p_dst - dst);
1178}
1179
1181{
1182 const size_t dst_maxncpy = BLI_STR_FORMAT_INT32_GROUPED_SIZE;
1183 BLI_string_debug_size(dst, dst_maxncpy);
1184 UNUSED_VARS_NDEBUG(dst_maxncpy);
1185
1187 const int num_len = int(SNPRINTF(src, "%d", num));
1188
1189 return BLI_str_format_int_grouped_ex(src, dst, num_len);
1190}
1191
1193{
1194 const size_t dst_maxncpy = BLI_STR_FORMAT_UINT64_GROUPED_SIZE;
1195 BLI_string_debug_size(dst, dst_maxncpy);
1196 UNUSED_VARS_NDEBUG(dst_maxncpy);
1197
1199 const int num_len = int(SNPRINTF(src, "%" PRIu64 "", num));
1200
1201 return BLI_str_format_int_grouped_ex(src, dst, num_len);
1202}
1203
1205{
1206 const size_t dst_maxncpy = BLI_STR_FORMAT_INT64_GROUPED_SIZE;
1207 BLI_string_debug_size(dst, dst_maxncpy);
1208 UNUSED_VARS_NDEBUG(dst_maxncpy);
1209
1211 const int num_len = int(SNPRINTF(src, "%" PRId64 "", num));
1212
1213 return BLI_str_format_int_grouped_ex(src, dst, num_len);
1214}
1215
1217 long long int bytes,
1218 const bool base_10)
1219{
1220 const size_t dst_maxncpy = BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE;
1221 BLI_string_debug_size(dst, dst_maxncpy);
1222
1223 double bytes_converted = double(bytes);
1224 int order = 0;
1225 int decimals;
1226 const int base = base_10 ? 1000 : 1024;
1227 const char *units_base_10[] = {"B", "KB", "MB", "GB", "TB", "PB"};
1228 const char *units_base_2[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB"};
1229 const int units_num = int(ARRAY_SIZE(units_base_2));
1230
1231 BLI_STATIC_ASSERT(ARRAY_SIZE(units_base_2) == ARRAY_SIZE(units_base_10), "array size mismatch");
1232
1233 while ((fabs(bytes_converted) >= base) && ((order + 1) < units_num)) {
1234 bytes_converted /= base;
1235 order++;
1236 }
1237 decimals = std::max(order - 1, 0);
1238
1239 /* Format value first, stripping away floating zeroes. */
1240 size_t len = BLI_snprintf_rlen(dst, dst_maxncpy, "%.*f", decimals, bytes_converted);
1241 len -= size_t(BLI_str_rstrip_float_zero(dst, '\0'));
1242 dst[len++] = ' ';
1243 BLI_strncpy(dst + len, base_10 ? units_base_10[order] : units_base_2[order], dst_maxncpy - len);
1244}
1245
1247 long long int bytes,
1248 const bool base_10)
1249{
1250 const size_t dst_maxncpy = BLI_STR_FORMAT_INT64_BYTE_UNIT_COMPACT_SIZE;
1251 BLI_string_debug_size(dst, dst_maxncpy);
1252
1253 float number_to_format_converted = float(bytes);
1254 int order = 0;
1255 const float base = base_10 ? 1000.0f : 1024.0f;
1256 const char *units[] = {"B", "K", "M", "G", "T", "P", "E"};
1257 const int units_num = int(ARRAY_SIZE(units));
1258
1259 while ((fabsf(number_to_format_converted) >= base) && ((order + 1) < units_num)) {
1260 number_to_format_converted /= base;
1261 order++;
1262 }
1263
1264 const bool add_dot = (llabs(bytes) > 99999) && fabsf(number_to_format_converted) > 99;
1265
1266 if (add_dot) {
1267 number_to_format_converted /= 100.0f;
1268 order++;
1269 }
1270
1271 BLI_snprintf(dst,
1272 dst_maxncpy,
1273 "%s%d%s",
1274 add_dot ? "." : "",
1275 int(floorf(fabsf(number_to_format_converted))),
1276 units[order]);
1277}
1278
1280 int number_to_format)
1281{
1283
1284 float number_to_format_converted = float(number_to_format);
1285 int order = 0;
1286 const float base = 1000.0f;
1287 const char *units[] = {"", "K", "M", "B"};
1288 const int units_num = int(ARRAY_SIZE(units));
1289
1290 while ((fabsf(number_to_format_converted) >= base) && ((order + 1) < units_num)) {
1291 number_to_format_converted /= base;
1292 order++;
1293 }
1294
1295 const size_t dst_maxncpy = BLI_STR_FORMAT_INT32_DECIMAL_UNIT_SIZE;
1296 int decimals = 0;
1297 if ((order > 0) && fabsf(number_to_format_converted) < 100.0f) {
1298 decimals = 1;
1299 }
1300 BLI_snprintf(dst, dst_maxncpy, "%.*f%s", decimals, number_to_format_converted, units[order]);
1301}
1302
1304 const int number_to_format)
1305{
1306 const size_t dst_maxncpy = BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE;
1307 BLI_string_debug_size(dst, dst_maxncpy);
1308
1309 float number_to_format_converted = float(number_to_format);
1310 int order = 0;
1311 const float base = 1000;
1312 const char *units[] = {"", "K", "M", "B"};
1313 const int units_num = int(ARRAY_SIZE(units));
1314
1315 while ((fabsf(number_to_format_converted) >= base) && ((order + 1) < units_num)) {
1316 number_to_format_converted /= base;
1317 order++;
1318 }
1319
1320 const bool add_dot = (abs(number_to_format) > 99999) && fabsf(number_to_format_converted) > 99;
1321
1322 if (add_dot) {
1323 number_to_format_converted /= 100;
1324 order++;
1325 }
1326
1327 BLI_snprintf(dst,
1328 dst_maxncpy,
1329 "%s%s%d%s",
1330 number_to_format < 0 ? "-" : "",
1331 add_dot ? "." : "",
1332 int(floorf(fabsf(number_to_format_converted))),
1333 units[order]);
1334}
1335
1337
1338/* -------------------------------------------------------------------- */
1341
1342#ifdef WITH_STRSIZE_DEBUG
1343void BLI_string_debug_size_after_nil(char *str, size_t str_maxncpy)
1344{
1345 /* Step over the nil, into the character afterwards. */
1346 size_t str_tail = BLI_strnlen(str, str_maxncpy) + 2;
1347 if (str_tail < str_maxncpy) {
1348 BLI_string_debug_size(str + str_tail, str_maxncpy - str_tail);
1349 }
1350}
1351
1352#endif /* WITH_STRSIZE_DEBUG */
1353
1355
1356} // namespace blender
#define BLI_STR_FORMAT_INT64_GROUPED_SIZE
Definition BLI_string.hh:25
#define BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE
Definition BLI_string.hh:31
#define SNPRINTF(dst, format,...)
#define BLI_STR_FORMAT_INT32_DECIMAL_UNIT_SIZE
Definition BLI_string.hh:37
#define BLI_string_debug_size_after_nil(str, str_maxncpy)
#define BLI_STR_FORMAT_INT32_GROUPED_SIZE
Definition BLI_string.hh:28
#define BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE
Definition BLI_string.hh:40
#define BLI_string_debug_size(str, str_maxncpy)
#define BLI_STR_FORMAT_UINT64_GROUPED_SIZE
Definition BLI_string.hh:22
#define BLI_STR_FORMAT_INT64_BYTE_UNIT_COMPACT_SIZE
Definition BLI_string.hh:34
Read Blender memory allocation and freeing.
int pad[32 - sizeof(int)]
#define UNUSED_VARS_NDEBUG(...)
#define BLI_INLINE
#define UNLIKELY(x)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define CASE_PAIR(value_src, value_dst)
#define MEM_realloc_uninitialized(vmemh, len)
constexpr int64_t size() const
#define str(s)
#define abs
#define PRIu64
Definition inttypes.h:132
#define PRId64
Definition inttypes.h:78
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
Definition math_dual.h:241
BMesh Iterators.
void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE], long long int bytes, bool base_10) ATTR_NONNULL(1)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int char char int BLI_strcasecmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void BLI_str_format_decimal_unit(char dst[BLI_STR_FORMAT_INT32_DECIMAL_UNIT_SIZE], int number_to_format) ATTR_NONNULL(1)
unsigned __int64 uint64_t
Definition BKE_text.h:91
__int64 int64_t
Definition BKE_text.h:90
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
size_t BLI_vsnprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format, va_list arg) ATTR_PRINTF_FORMAT(3
void BLI_str_toupper_ascii(char *str, size_t len) ATTR_NONNULL(1)
int char char int int int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int bool bool bool size_t BLI_str_partition(const char *str, const char delim[], const char **sep, const char **suf) ATTR_NONNULL(1
bool bool BLI_str_quoted_substr(const char *__restrict str, const char *__restrict prefix, char *result, size_t result_maxncpy)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
int bool bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(1
char * BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
size_t BLI_str_format_int64_grouped(char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE], int64_t num) ATTR_NONNULL(1)
int bool bool bool BLI_strn_endswith(const char *__restrict str, const char *__restrict end, size_t str_len) ATTR_NONNULL(1
bool BLI_string_has_word_prefix(const char *haystack, const char *needle, size_t needle_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_str_format_byte_unit_compact(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_COMPACT_SIZE], long long int bytes, bool base_10) ATTR_NONNULL(1)
size_t size_t const char * BLI_str_escape_find_quote(const char *str) ATTR_NONNULL(1)
char BLI_toupper_ascii(const char c) ATTR_WARN_UNUSED_RESULT
static int left_number_strcmp(const char *s1, const char *s2, int *tiebreaker)
int char * BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
size_t BLI_snprintf_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
bool bool int BLI_string_find_split_words(const char *str, size_t str_maxlen, char delim, int r_words[][2], int words_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int BLI_str_index_in_array(const char *__restrict str, const char **__restrict str_array) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
char char * BLI_strncpy_ensure_pad(char *__restrict dst, const char *__restrict src, char pad, size_t dst_maxncpy) ATTR_NONNULL(1
bool bool int bool BLI_string_elem_split_by_delim(const char *haystack, const char delim, const char *needle) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int char char int int BLI_strncasecmp(const char *s1, const char *s2, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
static size_t BLI_str_format_int_grouped_ex(char *src, char *dst, int num_len)
BLI_INLINE bool str_unescape_pair(char c_next, char *r_out)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
int BLI_str_rstrip_float_zero(char *str, char pad) ATTR_NONNULL(1)
char char size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int bool bool bool size_t size_t size_t int BLI_string_max_possible_word_count(int str_len) ATTR_WARN_UNUSED_RESULT
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
int char char int int int int size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_str_index_in_array_n(const char *__restrict str, const char **__restrict str_array, int str_array_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT const size_t num
size_t BLI_str_unescape_ex(char *__restrict dst, const char *__restrict src, size_t src_len, size_t dst_maxncpy, bool *r_is_complete) ATTR_NONNULL(1
char BLI_tolower_ascii(const char c) ATTR_WARN_UNUSED_RESULT
void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(1)
size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], int num) ATTR_NONNULL(1)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
bool BLI_str_quoted_substr_range(const char *__restrict str, const char *__restrict prefix, int *__restrict r_start, int *__restrict r_end) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
size_t size_t BLI_vsnprintf_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format, va_list arg) ATTR_PRINTF_FORMAT(3
void BLI_str_format_integer_unit(char dst[BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE], int number_to_format) ATTR_NONNULL(1)
int bool BLI_str_startswith(const char *__restrict str, const char *__restrict start) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void BLI_str_rstrip(char *str) ATTR_NONNULL(1)
size_t size_t char * BLI_sprintfN_with_buffer(char *fixed_buf, size_t fixed_buf_maxncpy, size_t *result_len, const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int bool bool bool size_t size_t size_t BLI_str_partition_ex(const char *str, const char *end, const char delim[], const char **sep, const char **suf, bool from_right) ATTR_NONNULL(1
int bool bool bool size_t size_t BLI_str_rpartition(const char *str, const char delim[], const char **sep, const char **suf) ATTR_NONNULL(1
size_t size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_len) ATTR_NONNULL(1
bool bool BLI_string_all_words_matched(const char *name, const char *str, int(*words)[2], int words_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
char char * BLI_vsprintfN(const char *__restrict format, va_list args) ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
int BLI_str_rstrip_digits(char *str) ATTR_NONNULL()
int BLI_strcaseeq(const char *a, const char *b) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int char char * BLI_strncasestr(const char *s, const char *find, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
char char size_t char * BLI_strncat(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE], uint64_t num) ATTR_NONNULL(1)
int char char int int int int BLI_strcmp_ignore_pad(const char *str1, const char *str2, char pad) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
char char size_t char const char * BLI_strchr_or_end(const char *str, char ch) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
char * BLI_vsprintfN_with_buffer(char *fixed_buf, size_t fixed_buf_maxncpy, size_t *result_len, const char *__restrict format, va_list args) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
#define floorf
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float