Merge branch 'blender-v2.93-release'

This commit is contained in:
Campbell Barton 2021-04-21 17:43:51 +10:00
commit f9867c1f11
2 changed files with 28 additions and 0 deletions

View File

@ -68,6 +68,11 @@ char *BLI_str_replaceN(const char *__restrict str,
void BLI_str_replace_char(char *string, char src, char dst) ATTR_NONNULL();
bool BLI_str_replace_table_exact(char *string,
const size_t string_len,
const char *replace_table[][2],
int replace_table_len);
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...)
ATTR_NONNULL(1, 3) ATTR_PRINTF_FORMAT(3, 4);
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...)

View File

@ -539,6 +539,29 @@ void BLI_str_replace_char(char *str, char src, char dst)
}
}
/**
* Simple exact-match string replacement.
*
* \param replace_table: Array of source, destination pairs.
*
* \note Larger tables should use a hash table.
*/
bool BLI_str_replace_table_exact(char *string,
const size_t string_len,
const char *replace_table[][2],
int replace_table_len)
{
for (int i = 0; i < replace_table_len; i++) {
if (STREQ(string, replace_table[i][0])) {
BLI_strncpy(string, replace_table[i][1], string_len);
return true;
}
}
return false;
}
/** \} */
/**
* Compare two strings without regard to case.
*