51char *
BLI_strdupcat(
const char *__restrict str1,
const char *__restrict str2)
54 const size_t str1_len = strlen(str1);
55 const size_t str2_len = strlen(str2) + 1;
61 memcpy(s, str1, str1_len);
63 memcpy(s, str2, str2_len);
68char *
BLI_strncpy(
char *__restrict dst,
const char *__restrict src,
const size_t dst_maxncpy)
75 memcpy(dst, src, srclen);
81 const char *__restrict src,
96 if (src[idx] !=
pad) {
103 if ((src[srclen - 1] !=
pad) && (srclen == dst_maxncpy)) {
107 memcpy(&dst[idx], src, srclen);
110 if (dst[idx - 1] !=
pad) {
119size_t BLI_strncpy_rlen(
char *__restrict dst,
const char *__restrict src,
const size_t dst_maxncpy)
126 memcpy(dst, src, srclen);
137char *
BLI_strncat(
char *__restrict dst,
const char *__restrict src,
const size_t dst_maxncpy)
142 if (
len < dst_maxncpy) {
156 const char *__restrict
format,
167 n = size_t(vsnprintf(dst, dst_maxncpy,
format, arg));
169 if (n !=
size_t(-1) && n < dst_maxncpy) {
173 dst[dst_maxncpy - 1] =
'\0';
181 const char *__restrict
format,
192 n = size_t(vsnprintf(dst, dst_maxncpy,
format, arg));
194 if (n !=
size_t(-1) && n < dst_maxncpy) {
221 const char *__restrict
format,
237 char *fixed_buf,
size_t fixed_buf_size,
size_t *result_len,
const char *__restrict
format, ...)
241 int retval = vsnprintf(fixed_buf, fixed_buf_size,
format, args);
246 if (
UNLIKELY(fixed_buf_size == 0)) {
252 *result_len = size_t(retval);
253 if (
size_t(retval) < fixed_buf_size) {
258 const size_t size = size_t(retval) + 1;
269 size_t fixed_buf_size,
271 const char *__restrict
format,
275 va_copy(args_copy, args);
276 int retval = vsnprintf(fixed_buf, fixed_buf_size,
format, args_copy);
281 if (
UNLIKELY(fixed_buf_size == 0)) {
287 *result_len = size_t(retval);
288 if (
size_t(retval) < fixed_buf_size) {
293 const size_t size = size_t(retval) + 1;
308 fixed_buf,
sizeof(fixed_buf), &result_len,
format, args);
310 if (
result != fixed_buf) {
313 size_t size = result_len + 1;
324 fixed_buf,
sizeof(fixed_buf), &result_len,
format, args);
325 if (
result != fixed_buf) {
328 size_t size = result_len + 1;
340size_t BLI_str_escape(
char *__restrict dst,
const char *__restrict src,
const size_t dst_maxncpy)
346 for (; (
len < dst_maxncpy) && (*src !=
'\0'); dst++, src++,
len++) {
348 if (
ELEM(c,
'\\',
'"') ||
349 ((c ==
'\t') && ((
void)(c =
't'),
true)) ||
350 ((c ==
'\n') && ((
void)(c =
'n'),
true)) ||
351 ((c ==
'\r') && ((
void)(c =
'r'),
true)) ||
352 ((c ==
'\a') && ((
void)(c =
'a'),
true)) ||
353 ((c ==
'\b') && ((
void)(c =
'b'),
true)) ||
354 ((c ==
'\f') && ((
void)(c =
'f'),
true)))
375 const size_t max_result_size = strlen(
str) * 2 + 1;
377 result.resize(max_result_size);
379 result.resize(result_size);
385#define CASE_PAIR(value_src, value_dst) \
387 *r_out = value_dst; \
405 const char *__restrict src,
406 const size_t src_maxncpy,
408 const size_t dst_maxncpy,
414 bool is_complete =
true;
415 const size_t max_strlen = dst_maxncpy - 1;
416 for (
const char *src_end = src + src_maxncpy; (src < src_end) && *src; src++) {
428 *r_is_complete = is_complete;
432size_t BLI_str_unescape(
char *__restrict dst,
const char *__restrict src,
const size_t src_maxncpy)
437 for (
const char *src_end = src + src_maxncpy; (src < src_end) && *src; src++) {
451 while (*
str && (*
str !=
'"' || escape)) {
454 escape = (escape ==
false) && (*
str ==
'\\');
457 return (*
str ==
'"') ?
str :
nullptr;
467 const char *__restrict prefix,
468 int *__restrict r_start,
469 int *__restrict r_end)
471 const char *str_start = strstr(
str, prefix);
472 if (str_start ==
nullptr) {
475 const size_t prefix_len = strlen(prefix);
478 "Zero length prefix passed in, "
479 "caller must prevent this from happening!");
483 "Prefix includes trailing quote, "
484 "caller must prevent this from happening!");
486 str_start += prefix_len;
496 *r_start = int(str_start -
str);
497 *r_end = int(str_end -
str);
515char *BLI_str_quoted_substrN(
const char *__restrict
str,
const char *__restrict prefix)
517 int start_match_ofs, end_match_ofs;
521 const size_t escaped_len = (size_t)(end_match_ofs - start_match_ofs);
524 if (unescaped_len != escaped_len) {
532 const char *__restrict prefix,
534 size_t result_maxncpy)
538 int start_match_ofs, end_match_ofs;
542 const size_t escaped_len = size_t(end_match_ofs - start_match_ofs);
545 if (is_complete ==
false) {
567 if ((c = *find++) != 0) {
568 c = char(tolower(c));
572 if ((sc = *s++) == 0) {
575 sc = char(tolower(sc));
585 return (str_len / 2) + 1;
592 if ((match == haystack) || (*(match - 1) ==
' ') || ispunct(*(match - 1))) {
606 for (index = 0; index < words_len; index++) {
611 const bool all_words_matched = (index == words_len);
613 return all_words_matched;
620 if ((c = *find++) != 0) {
621 c = char(tolower(c));
625 if ((sc = *s++) == 0) {
628 sc = char(tolower(sc));
635 if ((sc = *s++) == 0) {
638 sc = char(tolower(sc));
653 c1 = char(tolower(s1[
i]));
654 c2 = char(tolower(s2[
i]));
675 for (
i = 0;
i <
len;
i++) {
676 c1 = char(tolower(s1[
i]));
677 c2 = char(tolower(s2[
i]));
696 const char *p1 = s1, *p2 = s2;
697 int numdigit, numzero1, numzero2;
700 for (numzero1 = 0; *p1 ==
'0'; numzero1++) {
703 for (numzero2 = 0; *p2 ==
'0'; numzero2++) {
708 for (numdigit = 0;; numdigit++) {
709 if (isdigit(*(p1 + numdigit)) && isdigit(*(p2 + numdigit))) {
712 if (isdigit(*(p1 + numdigit))) {
715 if (isdigit(*(p2 + numdigit))) {
723 int compare = strncmp(p1, p2,
size_t(numdigit));
731 if (*tiebreaker == 0) {
732 if (numzero1 > numzero2) {
735 else if (numzero1 < numzero2) {
754 if (isdigit(s1[d1]) && isdigit(s2[d2])) {
757 if (numcompare != 0) {
763 while (isdigit(s1[d1])) {
767 while (isdigit(s2[d2])) {
773 if (
ELEM(0, s1[d1], s2[d2])) {
777 c1 = char(tolower(s1[d1]));
778 c2 = char(tolower(s2[d2]));
784 else if (c1 ==
'.') {
787 else if (c2 ==
'.') {
807 return strcmp(s1, s2);
812 size_t str1_len, str2_len;
814 while (*str1 ==
pad) {
817 while (*str2 ==
pad) {
821 str1_len = strlen(str1);
822 str2_len = strlen(str2);
824 while (str1_len && (str1[str1_len - 1] ==
pad)) {
827 while (str2_len && (str2[str2_len - 1] ==
pad)) {
831 if (str1_len == str2_len) {
832 return strncmp(str1, str2, str2_len);
834 if (str1_len > str2_len) {
835 int ret = strncmp(str1, str2, str2_len);
842 int ret = strncmp(str1, str2, str1_len);
857 const char **__restrict str_array,
858 const int str_array_len)
861 const char **str_iter = str_array;
863 for (index = 0; index < str_array_len; str_iter++, index++) {
874 const char **str_iter = str_array;
876 for (index = 0; *str_iter; str_iter++, index++) {
886 for (; *
str && *start;
str++, start++) {
887 if (*
str != *start) {
892 return (*start ==
'\0');
897 size_t end_len = strlen(end);
899 if (end_len <= str_len) {
900 const char *iter = &
str[str_len - end_len];
902 if (*iter++ != *end++) {
913 const size_t str_len = strlen(
str);
944 while (!
ELEM(*p, ch,
'\0')) {
958 return (c >=
'A' && c <=
'Z') ? c + (
'a' -
'A') : c;
963 return (c >=
'a' && c <=
'z') ? c - (
'a' -
'A') : c;
992 for (
int i =
int(strlen(
str)) - 1;
i >= 0;
i--) {
993 if (isspace(
str[
i])) {
1004 char *p = strchr(
str,
'.');
1009 end_p = p + (strlen(p) - 1);
1011 while (end_p != p && *end_p ==
'0') {
1025 int str_len = int(strlen(
str));
1026 while (str_len > 0 && isdigit(
str[--str_len])) {
1027 str[str_len] =
'\0';
1054 const bool from_right)
1060 *sep = *suf =
nullptr;
1062 for (d = delim; *d !=
'\0'; d++) {
1067 for (tmp = end - 1; (tmp >=
str) && (*tmp != *d); tmp--) {
1075 tmp = strchr(
str, *d);
1082 tmp = (from_right) ? strrchr(
str, *d) : strchr(
str, *d);
1085 if (tmp && (from_right ? (*sep < tmp) : (!*sep || *sep > tmp))) {
1092 return size_t(*sep -
str);
1095 return end ? size_t(end -
str) : strlen(
str);
1099 const char *
str,
const size_t str_maxlen,
const char delim,
int r_words[][2],
int words_max)
1102 bool charsearch =
true;
1105 for (
i = 0; (
i < int(str_maxlen)) && (
str[
i] !=
'\0');
i++) {
1106 if (
str[
i] != delim) {
1111 for (; (
i < int(str_maxlen)) && (
str[
i] !=
'\0') && (n < words_max);
i++) {
1112 if ((
str[
i] != delim) && (charsearch ==
true)) {
1117 if ((
str[
i] == delim) && (charsearch ==
false)) {
1118 r_words[n][1] =
i - r_words[n][0];
1125 if (charsearch ==
false) {
1126 r_words[n][1] =
i - r_words[n][0];
1136 const size_t needle_len = strlen(needle);
1137 const char *p = haystack;
1140 if ((
size_t(p_next - p) == needle_len) && (memcmp(p, needle, needle_len) == 0)) {
1143 if (*p_next ==
'\0') {
1162 const char separator =
',';
1165 if (*p_src ==
'-') {
1166 *p_dst++ = *p_src++;
1170 for (commas = 2 - num_len % 3; *p_src; commas = (commas + 1) % 3) {
1171 *p_dst++ = *p_src++;
1173 *p_dst++ = separator;
1178 return size_t(p_dst - dst);
1188 const int num_len = int(
SNPRINTF(src,
"%d",
num));
1206 long long int bytes,
1212 double bytes_converted = double(bytes);
1215 const int base = base_10 ? 1000 : 1024;
1216 const char *units_base_10[] = {
"B",
"KB",
"MB",
"GB",
"TB",
"PB"};
1217 const char *units_base_2[] = {
"B",
"KiB",
"MiB",
"GiB",
"TiB",
"PiB"};
1218 const int units_num = int(
ARRAY_SIZE(units_base_2));
1222 while ((
fabs(bytes_converted) >= base) && ((order + 1) < units_num)) {
1223 bytes_converted /= base;
1226 decimals = std::max(order - 1, 0);
1232 BLI_strncpy(dst +
len, base_10 ? units_base_10[order] : units_base_2[order], dst_maxncpy -
len);
1236 long long int bytes,
1242 float number_to_format_converted = float(bytes);
1244 const float base = base_10 ? 1000.0f : 1024.0f;
1245 const char *units[] = {
"B",
"K",
"M",
"G",
"T",
"P"};
1246 const int units_num = int(
ARRAY_SIZE(units));
1248 while ((
fabsf(number_to_format_converted) >= base) && ((order + 1) < units_num)) {
1249 number_to_format_converted /= base;
1253 const bool add_dot = (llabs(bytes) > 99999) &&
fabsf(number_to_format_converted) > 99;
1256 number_to_format_converted /= 100.0f;
1269 int number_to_format)
1273 float number_to_format_converted = float(number_to_format);
1275 const float base = 1000.0f;
1276 const char *units[] = {
"",
"K",
"M",
"B"};
1277 const int units_num = int(
ARRAY_SIZE(units));
1279 while ((
fabsf(number_to_format_converted) >= base) && ((order + 1) < units_num)) {
1280 number_to_format_converted /= base;
1286 if ((order > 0) &&
fabsf(number_to_format_converted) < 100.0f) {
1289 BLI_snprintf(dst, dst_maxncpy,
"%.*f%s", decimals, number_to_format_converted, units[order]);
1293 const int number_to_format)
1298 float number_to_format_converted = float(number_to_format);
1300 const float base = 1000;
1301 const char *units[] = {
"",
"K",
"M",
"B"};
1302 const int units_num = int(
ARRAY_SIZE(units));
1304 while ((
fabsf(number_to_format_converted) >= base) && ((order + 1) < units_num)) {
1305 number_to_format_converted /= base;
1309 const bool add_dot = (
abs(number_to_format) > 99999) &&
fabsf(number_to_format_converted) > 99;
1312 number_to_format_converted /= 100;
1319 number_to_format < 0 ?
"-" :
"",
1331#ifdef WITH_STRSIZE_DEBUG
1336 if (str_tail < str_maxncpy) {
#define BLI_STATIC_ASSERT(a, msg)
#define BLI_assert_msg(a, msg)
ATTR_WARN_UNUSED_RESULT const size_t num
#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(...)
Read Guarded memory(de)allocation.
int pad[32 - sizeof(int)]
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
#define MEM_reallocN(vmemh, len)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
ccl_device_inline float2 fabs(const float2 a)
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)