50char *
BLI_strdupcat(
const char *__restrict str1,
const char *__restrict str2)
53 const size_t str1_len = strlen(str1);
54 const size_t str2_len = strlen(str2) + 1;
60 memcpy(s, str1, str1_len);
62 memcpy(s, str2, str2_len);
67char *
BLI_strncpy(
char *__restrict dst,
const char *__restrict src,
const size_t dst_maxncpy)
74 memcpy(dst, src, srclen);
80 const char *__restrict src,
95 if (src[idx] !=
pad) {
102 if ((src[srclen - 1] !=
pad) && (srclen == dst_maxncpy)) {
106 memcpy(&dst[idx], src, srclen);
109 if (dst[idx - 1] !=
pad) {
118size_t BLI_strncpy_rlen(
char *__restrict dst,
const char *__restrict src,
const size_t dst_maxncpy)
125 memcpy(dst, src, srclen);
136char *
BLI_strncat(
char *__restrict dst,
const char *__restrict src,
const size_t dst_maxncpy)
141 if (
len < dst_maxncpy) {
155 const char *__restrict
format,
166 n = (size_t)vsnprintf(dst, dst_maxncpy,
format, arg);
168 if (n != (
size_t)-1 && n < dst_maxncpy) {
172 dst[dst_maxncpy - 1] =
'\0';
180 const char *__restrict
format,
191 n = (size_t)vsnprintf(dst, dst_maxncpy,
format, arg);
193 if (n != (
size_t)-1 && n < dst_maxncpy) {
220 const char *__restrict
format,
236 char *fixed_buf,
size_t fixed_buf_size,
size_t *result_len,
const char *__restrict
format, ...)
240 int retval = vsnprintf(fixed_buf, fixed_buf_size,
format, args);
245 if (
UNLIKELY(fixed_buf_size == 0)) {
251 *result_len = (size_t)retval;
252 if ((
size_t)retval < fixed_buf_size) {
257 const size_t size = (size_t)retval + 1;
258 char *result =
MEM_mallocN(
sizeof(
char) * size, __func__);
260 retval = vsnprintf(result, size,
format, args);
268 size_t fixed_buf_size,
270 const char *__restrict
format,
274 va_copy(args_copy, args);
275 int retval = vsnprintf(fixed_buf, fixed_buf_size,
format, args_copy);
280 if (
UNLIKELY(fixed_buf_size == 0)) {
286 *result_len = (size_t)retval;
287 if ((
size_t)retval < fixed_buf_size) {
292 const size_t size = (size_t)retval + 1;
293 char *result =
MEM_mallocN(
sizeof(
char) * size, __func__);
294 retval = vsnprintf(result, size,
format, args);
307 fixed_buf,
sizeof(fixed_buf), &result_len,
format, args);
309 if (result != fixed_buf) {
312 size_t size = result_len + 1;
313 result =
MEM_mallocN(
sizeof(
char) * size, __func__);
314 memcpy(result, fixed_buf, size);
323 fixed_buf,
sizeof(fixed_buf), &result_len,
format, args);
324 if (result != fixed_buf) {
327 size_t size = result_len + 1;
328 result =
MEM_mallocN(
sizeof(
char) * size, __func__);
329 memcpy(result, fixed_buf, size);
339size_t BLI_str_escape(
char *__restrict dst,
const char *__restrict src,
const size_t dst_maxncpy)
345 for (; (
len < dst_maxncpy) && (*src !=
'\0'); dst++, src++,
len++) {
347 if (
ELEM(c,
'\\',
'"') ||
348 ((c ==
'\t') && ((
void)(c =
't'),
true)) ||
349 ((c ==
'\n') && ((void)(c =
'n'),
true)) ||
350 ((c ==
'\r') && ((
void)(c =
'r'),
true)) ||
351 ((c ==
'\a') && ((void)(c =
'a'),
true)) ||
352 ((c ==
'\b') && ((
void)(c =
'b'),
true)) ||
353 ((c ==
'\f') && ((void)(c =
'f'),
true)))
371#define CASE_PAIR(value_src, value_dst) \
373 *r_out = value_dst; \
391 const char *__restrict src,
392 const size_t src_maxncpy,
394 const size_t dst_maxncpy,
400 bool is_complete =
true;
401 const size_t max_strlen = dst_maxncpy - 1;
402 for (
const char *src_end = src + src_maxncpy; (src < src_end) && *src; src++) {
414 *r_is_complete = is_complete;
418size_t BLI_str_unescape(
char *__restrict dst,
const char *__restrict src,
const size_t src_maxncpy)
423 for (
const char *src_end = src + src_maxncpy; (src < src_end) && *src; src++) {
437 while (*
str && (*
str !=
'"' || escape)) {
440 escape = (escape ==
false) && (*
str ==
'\\');
453 const char *__restrict prefix,
454 int *__restrict r_start,
455 int *__restrict r_end)
457 const char *str_start = strstr(
str, prefix);
458 if (str_start ==
NULL) {
461 const size_t prefix_len = strlen(prefix);
464 "Zero length prefix passed in, "
465 "caller must prevent this from happening!");
469 "Prefix includes trailing quote, "
470 "caller must prevent this from happening!");
472 str_start += prefix_len;
482 *r_start = (
int)(str_start -
str);
483 *r_end = (
int)(str_end -
str);
501char *BLI_str_quoted_substrN(
const char *__restrict
str,
const char *__restrict prefix)
503 int start_match_ofs, end_match_ofs;
507 const size_t escaped_len = (size_t)(end_match_ofs - start_match_ofs);
508 char *result =
MEM_mallocN(
sizeof(
char) * (escaped_len + 1), __func__);
510 if (unescaped_len != escaped_len) {
511 result =
MEM_reallocN(result,
sizeof(
char) * (unescaped_len + 1));
518 const char *__restrict prefix,
520 size_t result_maxncpy)
524 int start_match_ofs, end_match_ofs;
528 const size_t escaped_len = (size_t)(end_match_ofs - start_match_ofs);
531 if (is_complete ==
false) {
553 if ((c = *find++) != 0) {
554 c = (char)tolower(c);
558 if ((sc = *s++) == 0) {
561 sc = (char)tolower(sc);
571 return (str_len / 2) + 1;
578 if ((match == haystack) || (*(match - 1) ==
' ') || ispunct(*(match - 1))) {
592 for (index = 0; index < words_len; index++) {
597 const bool all_words_matched = (index == words_len);
599 return all_words_matched;
606 if ((c = *find++) != 0) {
607 c = (char)tolower(c);
611 if ((sc = *s++) == 0) {
614 sc = (char)tolower(sc);
621 if ((sc = *s++) == 0) {
624 sc = (char)tolower(sc);
639 c1 = (char)tolower(s1[i]);
640 c2 = (char)tolower(s2[i]);
661 for (i = 0; i <
len; i++) {
662 c1 = (char)tolower(s1[i]);
663 c2 = (char)tolower(s2[i]);
682 const char *p1 = s1, *p2 = s2;
683 int numdigit, numzero1, numzero2;
686 for (numzero1 = 0; *p1 ==
'0'; numzero1++) {
689 for (numzero2 = 0; *p2 ==
'0'; numzero2++) {
694 for (numdigit = 0;; numdigit++) {
695 if (isdigit(*(p1 + numdigit)) && isdigit(*(p2 + numdigit))) {
698 if (isdigit(*(p1 + numdigit))) {
701 if (isdigit(*(p2 + numdigit))) {
709 int compare = (
int)strncmp(p1, p2, (
size_t)numdigit);
717 if (*tiebreaker == 0) {
718 if (numzero1 > numzero2) {
721 else if (numzero1 < numzero2) {
740 if (isdigit(s1[d1]) && isdigit(s2[d2])) {
743 if (numcompare != 0) {
749 while (isdigit(s1[d1])) {
753 while (isdigit(s2[d2])) {
759 if (
ELEM(0, s1[d1], s2[d2])) {
763 c1 = (char)tolower(s1[d1]);
764 c2 = (char)tolower(s2[d2]);
770 else if (c1 ==
'.') {
773 else if (c2 ==
'.') {
793 return strcmp(s1, s2);
798 size_t str1_len, str2_len;
800 while (*str1 ==
pad) {
803 while (*str2 ==
pad) {
807 str1_len = strlen(str1);
808 str2_len = strlen(str2);
810 while (str1_len && (str1[str1_len - 1] ==
pad)) {
813 while (str2_len && (str2[str2_len - 1] ==
pad)) {
817 if (str1_len == str2_len) {
818 return strncmp(str1, str2, str2_len);
820 if (str1_len > str2_len) {
821 int ret = strncmp(str1, str2, str2_len);
828 int ret = strncmp(str1, str2, str1_len);
843 const char **__restrict str_array,
844 const int str_array_len)
847 const char **str_iter = str_array;
849 for (index = 0; index < str_array_len; str_iter++, index++) {
860 const char **str_iter = str_array;
862 for (index = 0; *str_iter; str_iter++, index++) {
872 for (; *
str && *start;
str++, start++) {
873 if (*
str != *start) {
878 return (*start ==
'\0');
883 size_t end_len = strlen(end);
885 if (end_len < str_len) {
886 const char *iter = &
str[str_len - end_len];
888 if (*iter++ != *end++) {
899 const size_t str_len = strlen(
str);
930 while (!
ELEM(*p, ch,
'\0')) {
944 return (c >=
'A' && c <=
'Z') ? c + (
'a' -
'A') : c;
949 return (c >=
'a' && c <=
'z') ? c - (
'a' -
'A') : c;
956 for (i = 0; (i <
len) &&
str[i]; i++) {
965 for (i = 0; (i <
len) &&
str[i]; i++) {
978 for (
int i = (
int)strlen(
str) - 1; i >= 0; i--) {
979 if (isspace(
str[i])) {
990 char *p = strchr(
str,
'.');
995 end_p = p + (strlen(p) - 1);
997 while (end_p != p && *end_p ==
'0') {
1011 int str_len = (
int)strlen(
str);
1012 while (str_len > 0 && isdigit(
str[--str_len])) {
1013 str[str_len] =
'\0';
1040 const bool from_right)
1043 char *(*func)(
const char *
str,
int c) = from_right ? strrchr : strchr;
1049 for (d = delim; *d !=
'\0'; d++) {
1054 for (tmp = end - 1; (tmp >=
str) && (*tmp != *d); tmp--) {
1062 tmp = func(
str, *d);
1069 tmp = func(
str, *d);
1072 if (tmp && (from_right ? (*sep < tmp) : (!*sep || *sep > tmp))) {
1079 return (
size_t)(*sep -
str);
1082 return end ? (size_t)(end -
str) : strlen(
str);
1086 const char *
str,
const size_t str_maxlen,
const char delim,
int r_words[][2],
int words_max)
1089 bool charsearch =
true;
1092 for (i = 0; (i < (
int)str_maxlen) && (
str[i] !=
'\0'); i++) {
1093 if (
str[i] != delim) {
1098 for (; (i < (
int)str_maxlen) && (
str[i] !=
'\0') && (n < words_max); i++) {
1099 if ((
str[i] != delim) && (charsearch ==
true)) {
1104 if ((
str[i] == delim) && (charsearch ==
false)) {
1105 r_words[n][1] = i - r_words[n][0];
1112 if (charsearch ==
false) {
1113 r_words[n][1] = i - r_words[n][0];
1123 const size_t needle_len = strlen(needle);
1124 const char *p = haystack;
1127 if (((
size_t)(p_next - p) == needle_len) && (memcmp(p, needle, needle_len) == 0)) {
1130 if (*p_next ==
'\0') {
1149 const char separator =
',';
1152 if (*p_src ==
'-') {
1153 *p_dst++ = *p_src++;
1157 for (commas = 2 - num_len % 3; *p_src; commas = (commas + 1) % 3) {
1158 *p_dst++ = *p_src++;
1160 *p_dst++ = separator;
1165 return (
size_t)(p_dst - dst);
1175 const int num_len = (
int)
SNPRINTF(src,
"%d", num);
1193 long long int bytes,
1199 double bytes_converted = (
double)bytes;
1202 const int base = base_10 ? 1000 : 1024;
1203 const char *units_base_10[] = {
"B",
"KB",
"MB",
"GB",
"TB",
"PB"};
1204 const char *units_base_2[] = {
"B",
"KiB",
"MiB",
"GiB",
"TiB",
"PiB"};
1205 const int units_num =
ARRAY_SIZE(units_base_2);
1209 while ((
fabs(bytes_converted) >= base) && ((order + 1) < units_num)) {
1210 bytes_converted /= base;
1213 decimals =
MAX2(order - 1, 0);
1219 BLI_strncpy(dst +
len, base_10 ? units_base_10[order] : units_base_2[order], dst_maxncpy -
len);
1223 long long int bytes,
1229 float number_to_format_converted = (
float)bytes;
1231 const int base = base_10 ? 1000 : 1024;
1232 const char *units[] = {
"B",
"K",
"M",
"G",
"T",
"P"};
1235 while ((
fabsf(number_to_format_converted) >= base) && ((order + 1) < units_num)) {
1236 number_to_format_converted /= (
float)base;
1240 const bool add_dot = (llabs(bytes) > 99999) &&
fabsf(number_to_format_converted) > 99;
1243 number_to_format_converted /= 100.0f;
1256 int number_to_format)
1260 float number_to_format_converted = (
float)number_to_format;
1262 const float base = 1000;
1263 const char *units[] = {
"",
"K",
"M",
"B"};
1266 while ((
fabsf(number_to_format_converted) >= base) && ((order + 1) < units_num)) {
1267 number_to_format_converted /= base;
1273 if ((order > 0) &&
fabsf(number_to_format_converted) < 100.0f) {
1276 BLI_snprintf(dst, dst_maxncpy,
"%.*f%s", decimals, number_to_format_converted, units[order]);
1280 const int number_to_format)
1285 float number_to_format_converted = (
float)number_to_format;
1287 const float base = 1000;
1288 const char *units[] = {
"",
"K",
"M",
"B"};
1291 while ((
fabsf(number_to_format_converted) >= base) && ((order + 1) < units_num)) {
1292 number_to_format_converted /= base;
1296 const bool add_dot = (
abs(number_to_format) > 99999) &&
fabsf(number_to_format_converted) > 99;
1299 number_to_format_converted /= 100;
1306 number_to_format < 0 ?
"-" :
"",
1318#ifdef WITH_STRSIZE_DEBUG
1323 if (str_tail < str_maxncpy) {
#define BLI_STATIC_ASSERT(a, msg)
#define BLI_assert_msg(a, msg)
#define BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE
#define SNPRINTF(dst, format,...)
#define BLI_STR_FORMAT_INT32_DECIMAL_UNIT_SIZE
#define BLI_string_debug_size_after_nil(str, str_maxncpy)
#define BLI_STR_FORMAT_INT32_GROUPED_SIZE
#define BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE
#define BLI_string_debug_size(str, str_maxncpy)
#define BLI_STR_FORMAT_UINT64_GROUPED_SIZE
#define BLI_STR_FORMAT_INT64_BYTE_UNIT_COMPACT_SIZE
#define UNUSED_VARS_NDEBUG(...)
typedef double(DMatrix)[4][4]
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
int pad[32 - sizeof(int)]
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void *(* MEM_mallocN)(size_t len, const char *str)
void *(* MEM_callocN)(size_t len, const char *str)
ccl_device_inline float2 fabs(const float2 a)
unsigned __int64 uint64_t
int BLI_str_index_in_array(const char *__restrict str, const char **__restrict str_array)
size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], int num)
#define CASE_PAIR(value_src, value_dst)
char * BLI_strdupn(const char *str, const size_t len)
static int left_number_strcmp(const char *s1, const char *s2, int *tiebreaker)
char * BLI_strncasestr(const char *s, const char *find, size_t len)
int BLI_strcasecmp(const char *s1, const char *s2)
void BLI_str_format_decimal_unit(char dst[BLI_STR_FORMAT_INT32_DECIMAL_UNIT_SIZE], int number_to_format)
size_t BLI_str_partition(const char *str, const char delim[], const char **sep, const char **suf)
bool BLI_string_has_word_prefix(const char *haystack, const char *needle, size_t needle_len)
int BLI_string_max_possible_word_count(const int str_len)
void BLI_str_format_byte_unit_compact(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_COMPACT_SIZE], long long int bytes, const bool base_10)
bool BLI_string_all_words_matched(const char *name, const char *str, int(*words)[2], const int words_len)
void BLI_str_rstrip(char *str)
void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE], long long int bytes, const bool base_10)
char * BLI_vsprintfN(const char *__restrict format, va_list args)
int BLI_strcmp_ignore_pad(const char *str1, const char *str2, const char pad)
int BLI_str_index_in_array_n(const char *__restrict str, const char **__restrict str_array, const int str_array_len)
char * BLI_strcasestr(const char *s, const char *find)
int BLI_strcasecmp_natural(const char *s1, const char *s2)
int BLI_strncasecmp(const char *s1, const char *s2, size_t len)
size_t BLI_snprintf_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...)
char BLI_toupper_ascii(const char c)
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...)
char * BLI_vsprintfN_with_buffer(char *fixed_buf, size_t fixed_buf_size, size_t *result_len, const char *__restrict format, va_list args)
void BLI_str_format_integer_unit(char dst[BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE], const int number_to_format)
bool BLI_str_quoted_substr_range(const char *__restrict str, const char *__restrict prefix, int *__restrict r_start, int *__restrict r_end)
int BLI_string_find_split_words(const char *str, const size_t str_maxlen, const char delim, int r_words[][2], int words_max)
char * BLI_strdup_null(const char *str)
size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy)
void BLI_str_tolower_ascii(char *str, const size_t len)
size_t BLI_str_partition_ex(const char *str, const char *end, const char delim[], const char **sep, const char **suf, const bool from_right)
size_t BLI_str_rpartition(const char *str, const char delim[], const char **sep, const char **suf)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy)
size_t BLI_vsnprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format, va_list arg)
bool BLI_strn_endswith(const char *__restrict str, const char *__restrict end, size_t str_len)
char * BLI_sprintfN_with_buffer(char *fixed_buf, size_t fixed_buf_size, size_t *result_len, const char *__restrict format,...)
size_t BLI_strnlen(const char *str, const size_t maxlen)
size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const size_t src_maxncpy)
char * BLI_strncpy_ensure_pad(char *__restrict dst, const char *__restrict src, const char pad, size_t dst_maxncpy)
BLI_INLINE bool str_unescape_pair(char c_next, char *r_out)
size_t BLI_vsnprintf_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format, va_list arg)
char * BLI_sprintfN(const char *__restrict format,...)
size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy)
char BLI_tolower_ascii(const char c)
bool BLI_string_elem_split_by_delim(const char *haystack, const char delim, const char *needle)
static size_t BLI_str_format_int_grouped_ex(char *src, char *dst, int num_len)
const char * BLI_str_escape_find_quote(const char *str)
const char * BLI_strchr_or_end(const char *str, const char ch)
bool BLI_str_quoted_substr(const char *__restrict str, const char *__restrict prefix, char *result, size_t result_maxncpy)
void BLI_str_toupper_ascii(char *str, const size_t len)
bool BLI_str_endswith(const char *__restrict str, const char *__restrict end)
size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE], uint64_t num)
char * BLI_strdupcat(const char *__restrict str1, const char *__restrict str2)
size_t BLI_str_unescape_ex(char *__restrict dst, const char *__restrict src, const size_t src_maxncpy, const size_t dst_maxncpy, bool *r_is_complete)
int BLI_str_rstrip_float_zero(char *str, const char pad)
char * BLI_strncat(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy)
char * BLI_strdup(const char *str)
bool BLI_str_startswith(const char *__restrict str, const char *__restrict start)
int BLI_strcaseeq(const char *a, const char *b)
int BLI_str_rstrip_digits(char *str)
ccl_device_inline int abs(int x)